android - 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]
,我的服务器没有收到任何请求。)
我一直在网上寻找,仍然没有解决这个问题。请帮忙。
解决方案
这不是关于 Blob,而是更多关于你去的错误。所以不知道能不能帮到...
我发现我需要将 Mime Type 与要上传的文件匹配。
formData.append('file', {
uri : "file://...",
name : "filename.mp4",
type: "video/mp4",
});
推荐阅读
- android - 如何在颤动中保持按钮的状态?
- python - 为什么openCV蒙版将整个图像变黑?
- reactjs - Material-Table如何实现表格虚拟化和无限滚动?
- javascript - Cordova 音乐控制插件,如何使其工作?
- python - 使用 MultiIndex 删除 DataFrame 中的对称对
- git - 如何将一个 repo 移动到另一个 repo 文件夹并保留 git 历史记录?
- sql - 如何计算每个产品每天的库存给定天数在 PostgreSQL 之间缺失?
- c# - Identity Server 4 向用户添加自定义声明
- xml - 在 Snowflake 中解析嵌套的 XML
- python - Matplotlib 标签更改灰色阴影