首页 > 解决方案 > Expo android网络请求失败

问题描述

我想将一个 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],我的服务器没有收到任何请求。)

我一直在网上寻找,仍然没有解决这个问题。请帮忙。

标签: androidreact-nativeexpo

解决方案


这不是关于 Blob,而是更多关于你去的错误。所以不知道能不能帮到...

我发现我需要将 Mime Type 与要上传的文件匹配。

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

推荐阅读