response is a blob....
writeBlob(response){
return RNFS.writeFile(this.path + '/' + 'first.pdf', response, 'base64')
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
},
Have the same issue. Is there a solution?
Same, I've got a blob but i've no idea how to write it to disk
I'm not sure but, according to this issue, it seems Blob objects does not have correct functionality in react native ?
same question here.
I always use downloadFile() for dealing with binary data. It is doing an asynchronous GET-request to a specific URL and stores the response binary on device.
@itinance in my particular case, the binary content depends on the request, so I don't have the concept of one URL for the data.
have you tried to use 'ascii' to encode you binary data. and write the ascii string to file.
Here is a sample in node runtime:
const buffer = fs.readFileSync('./test.png');
for (let i = 0; i < buffer.length; i++) {
const num = buffer[i];
const str = String.fromCharCode(num);
fs.appendFileSync('./test1.png', str, { encoding: 'ascii' });
}
ASCII is not better fit for large data as it will affect performance exponentially. Better to use base64 or utf8 they are faster enough.
Use RNFetchBlob.fetch() instead of the fetch API.
Then the following code will work
RNFS.writeFile(filename, response.data, 'base64')
Most helpful comment
Use RNFetchBlob.fetch() instead of the fetch API.
Then the following code will work
RNFS.writeFile(filename, response.data, 'base64')