ReactNativeBlobUtil.fetchBlobForm failed to create request body
See original GitHub issueNo matter what I do, I get this Error message in iOS (not in Android, there it works) :
ReactNativeBlobUtil.fetchBlobForm failed to create request body
- “react-native-blob-util”: “^0.13.18”
- “react-native”: “0.66.2”,
- Testing in XCode Simulator, iPhone 13, iOS 15.0
- Using this for
data:
formData.push({
name: el.fileName,
filename: el.fileName,
type: el.type,
// Change BASE64 encoded data to a file path with prefix `ReactNativeBlobUtil-file://`.
// Or simply wrap the file path with ReactNativeBlobUtil.wrap().
data: ReactNativeBlobUtil.wrap(
decodeURIComponent(
Platform.OS === 'ios' ? el.uri.replace('file://', '') : el.uri,
),
),
});
I also tried other code, nothing works:
data: ReactNativeBlobUtil.wrap(el.uri)
OR
data: ReactNativeBlobUtil.wrap(decodeURIComponent(el.uri))
Does someone know what else can be done? Thank you.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
RNFetchBlob.fetchBlobForm failed to create request body #437
I am trying to upload a selected image from the camera roll using react-native-image-picker. The following works fine on Android but on ios...
Read more >rn-fetch-blob Error: RNFetchBlob.fetchBlobForm failed to ...
postFileUpload undefined Error: RNFetchBlob.fetchBlobForm failed to create request body at index.js:313 at MessageQueue.
Read more >react-native-blob-util - npm
Start using react-native-blob-util in your project by running `npm i ... If you're going to use a file as request body, just wrap...
Read more >rn-fetch-blob Error: RNFetchBlob.fetchBlobForm failed to ...
Coding example for the question rn-fetch-blob Error: RNFetchBlob.fetchBlobForm failed to create request body-Reactjs.
Read more >RNFetchBlob.fetchBlobForm failed to create request body
Coming soon: A brand new website interface for an even better experience!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Came across this issue in one of our apps and after some digging this is what solved it for me. Sorry in advance for the verbosity.
NOTE: It was only affecting iOS and not Android but always safe to check both. Also, just for context, we were saving everything under the ‘DocumentsDirectoryPath’ since it was available on both OS’s.
Problem 1 – ReactNativeBlobUtil.fetchBlobForm request body error
In one of the old forks of this AMAZING library they had the same issue found here. Some comments in there actually solved my problem when trying to use a file as a request body.
Problem 1 solved!
Alternate Solution to Problem 1
*** If this is consistent then it would mean that it’s not a problem with the library but problems with dealing with the intricacies of each OS and pathing ***
Sometimes trying to parse out that
file://didn’t work and the error still persisted. Another thing I noticed was that if this happened, just re-generating the file uri from scratch resolved the issue without having to remove thefile://part of the string in iOS. Both iOS and Android still working with thefile://in the string after usingwrap. For example,Problem 1 solved – again!
Problem 2 – Images go blank on app update
Now this may not be the best place to put this but just in case someone goes down the same rabbit hole – here it is!
A little background, we had an app published, we released new updates yada yada yada, and then noticed the images being saved from our form data are no longer viewable on iOS (but only after app updates which can replicated by just rebuilding the app if you are testing on an emulator and need to reproduce this). The images went blank but it still new that something was there, giving us hope that it wasn’t actually ‘corrupted.’
In the README of this library I found this note on readFile that led me to believe this is part of the issue of our current implementation.
We were saving the the absolute path to the local db and just using that stored string, the image uri, to display the image. Sounds straight forward and easy but for some reason on iOS it doesn’t behave as you would expect, as mentioned in the ‘readFile’ url above it states:
In conclusion, this is what I had to change in order for images to not get ‘corrupted’ (images go blank/black/etc) on my application.
** Keeping in mind that it wasn’t effecting Android and was only needed for iOS but most likely can be used for both OS’s. **
The new sourceUri created for iOS fixed my issue and now Problem 2 is solved!
Hi @RonRadtke This happened again to one of our users. Did something change since Jan 2022 that may have solved this issue?
Thanks!