ssomnoremac
ssomnoremac

Reputation: 759

Use fetch to post a blob in react-native

I'm trying to post a blob. It's definitely a blob. This isn't working in react-native though. I'm getting a red screen that says "PUT must have a request body". Well, I've put the blob in the request body.

createAttachment: function(url, blob) {
  var settings = {
    method: "PUT",
    headers: {
      'Accept': 'image/jpeg',
      'Content-Type': 'image/jpeg',
      'If-Match': '*',
    },
    body: blob
  };
  return fetch(url, settings)
}

Upvotes: 6

Views: 13172

Answers (2)

Xeijp
Xeijp

Reputation: 873

My project had same problem before, according to this issue perhaps, blob data is not supported in react native fetch API currently (Both in send and receive).

So I made a module myself ..

https://github.com/wkh237/react-native-fetch-blob

It works fine in our project, if you don't mind to take a look, it might helps.

Upvotes: 11

Related Questions