Expo Android网络请求失败

时间:2020-05-31 09:09:43

标签: android react-native expo

我想将wav文件(在blob中)发布到我的服务器上。

我已经使用邮递员测试了服务器,并且运行正常。

我还创建了一个react-app(web)并使用以下相同的逻辑成功发布了wav。

const formData = new FormData();
formData.append('file', blob, 'test');

let requestOptions = {
  method: 'POST',
  body: formData,
  mode:'no-cors',
};

// not localhost
fetch('http://xx.xx.xx.xx', requestOptions)
    .then(response => response.text())
    .then(result => {
      console.log(result)
    })
    .catch(error => console.log('error', error));

但是,我什至无法通过手机发送请求(只有[TypeError: Network request failed],服务器没有收到任何请求。)

我一直在网上寻找,仍然无法解决此问题。请帮忙。

1 个答案:

答案 0 :(得分:0)

这与Blob无关,而与错误有关。 所以不确定是否可以帮忙...

我发现我需要输入Mime类型以匹配要上传的文件。

formData.append('file', {
  uri : "file://...",
  name : "filename.mp4",
  type: "video/mp4",
});