Drop In Fetch with base64 string and application/octet-stream header does not work on iOS
suparngp opened this issue · 0 comments
R/N: 0.68.5
rn-fetch-blob: 0.12.0
Using the Fetch
polyfill does not work on iOS with a base64 string and application/octet-stream
.
const Fetch = RNFetchBlob.polyfill.Fetch as any
const blobFetch = new Fetch({
// enable this option so that the response data conversion handled automatically
auto: true,
}).build()
The constructor in Fetch
runs JSON.stringify
on the body
which wraps it in quotes.
https://github.com/joltup/rn-fetch-blob/blob/master/polyfill/Fetch.js#L52
Then RNFetchBlobRequestBuilder
on line https://github.com/joltup/rn-fetch-blob/blob/master/ios/RNFetchBlobReqBuilder.m#L159 tries to create an NSData
which returns nil.
This same logic also runs on Android.
https://github.com/joltup/rn-fetch-blob/blob/master/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java#L174
But it succeeds. It seems like Base64.decode(rawBody, 0)
is more forgiving than NSData
initializer and ignores additional quotes around a string.