Reputation: 1231
I am working on a react native project where i have to upload an image to my company specified cloud services (which i cant disclose here) which requires XMLHttpRequest Level 2, FileReader and Blob support.
var srcData = new Blob([base64Data], {type: 'image/jpeg'});
I have to use the above variable srcData
in a service call as a parameter which will upload the file into the cloud and provide me a callback with its url. I use this URL to update user Object in my database.
But i was facing an issue with the keyword Blob
. After spending some time investigating, i figured out that upgrading to react native 0.54 version solved the issue with Blob
keyword.
I am not able to understand where i am going wrong and does react native support Blob, XMLHttpRequest or fileReader? Is there any way i can solve this issue?
Any lead would be highly appreciated. Thank you in advance.
Upvotes: 5
Views: 13820
Reputation: 22209
As per the docs
var aBlob = new Blob( array[, options]);
where array is an Array of ArrayBuffer
, ArrayBufferView
, Blob
, DOMString
or a mix of any of such objects.
Base64
comprises of neither of the above, it just represents binary data in an ASCII string format by translating it into a radix-64 representation.
Since you already have base64
, therefore the best way to generate a blob
from it, without including any external libraries would be
export const generateBlob = base64URL => fetch(base64URL)
.then(response => response.blob())
.then(response => console.log('Your blob is' + response)
Upvotes: -4