Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6215

How to get blob of an locally saved image?

$
0
0

I am using “expo”: “38.0.8” to develop iOS and Android application.Currently I am trying to upload blob of an image to company server, sending it with custom Axios Post method, packing blob as one part of data.

I get the image from the device locally:

const imagePicker = camera ? ImagePicker.launchCameraAsync : ImagePicker.launchImageLibraryAsync;let image = await imagePicker({   mediaTypes: ImagePicker.MediaTypeOptions.Images,   allowsEditing: true,   quality: 1});The problem for me is to create blob and checking if it was created.I have tried:    fetch(image.uri)      .then(response =>        response.blob()        .then(blob => {           console.log(blob)        })     );and:    const blob = await new Promise((resolve, reject) => {      const xhr = new XMLHttpRequest();      xhr.onload = function() {        resolve(xhr.response);      };      xhr.onerror = function() {        reject(new TypeError('Network request failed'));      };      xhr.responseType = 'blob';      //@ts-ignore      xhr.open('GET', image.uri, true);      xhr.send(null);        }).then(blob => {           console.log(blob)           }    );

But both of them return me error: value.hasOwnProperty is not a function.The weird thing is that if try to display blob.size it works.Am I doing something wrong, is there a way to display blob or is blob not supported?

Thanks for any advice


Viewing all articles
Browse latest Browse all 6215

Trending Articles