Can't fetch file with XMLHttpRequest in React Native

Viewed 530

I'm trying to retrieve a local file on an iOS device which is saved from Expo Camera and ImageManipulator. The Image shows up in a View. However, when I run this code to get a blob and then upload to Firebase Storage, I get the 'Network request failed error', it seems random and I don't know what causes it.

The code is from here: https://github.com/expo/expo/issues/2402#issuecomment-443726662

const blob = yield new Promise((resolve, reject) => {
  const xhr = new XMLHttpRequest();
  xhr.onload = function() {
    resolve(xhr.response);
  };
  xhr.onerror = function(e) {
    //console.log(e);
    reject('Network request failed.');
  };
  xhr.responseType = 'blob';
  xhr.open('GET', uri, true);
  xhr.send(null);
})
.catch(e => console.log(e));
0 Answers
Related