无法在React Native中使用XMLHttpRequest提取文件

时间:2018-12-22 04:00:22

标签: javascript react-native xmlhttprequest blob expo

我正在尝试在iOS设备上检索从Expo Camera和ImageManipulator保存的本地文件。图像显示在视图中。但是,当我运行此代码以获取Blob,然后将其上传到Firebase Storage时,出现“网络请求失败错误”,这似乎是随机的,我不知道是什么原因引起的。

代码从这里: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 个答案:

没有答案