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)
}
This project was started in the cause of solving issue facebook/react-native#854, React Native's lacks of Blob implementation which results into problems when transferring binary data. It is committed to making file access and transfer easier and more efficient for React Native developers.
For this purpose, the fetch API provides a generic definition for the Request and Response objects as well as other aspects of network requests, serving as a mechanism to retrieve resources and interact with a REST API or the cloud. As described in the React Native docs: "React Native provides the Fetch API for your networking needs.
This sends the same POST request from React using fetch, but this version uses React hooks from a function component instead of lifecycle methods from a traditional React class component. The useEffect React hook replaces the componentDidMount lifecycle method to make the HTTP POST request when the component loads.
Linking can be skipped when the project uses React Native 0.60 or greater, because autolinking will take care of it If CocoaPods is used in the project, make sure to install the pod:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With