react-native - React Native,在使用 Axios 发布 FormData 时出现网络错误
问题描述
我正在尝试通过创建 FormData 来发送音频/图像。
我当前的版本是:“react-native”:“0.59.10”,“axios”:“^0.19.2”,“react”:“16.8.3”。我正在我的安卓设备上测试我的应用程序
并在发送 FormData 时每次都收到“网络错误”。
这是我创建和发送帖子的方式;
let new_options = {
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': myAuthorization
}
};
const content = new FormData();
content.append('file', {
uri: 'file://' + attachment.path,
name: 'test',
type: attachment.type
});
content.append('ReportId', report_id);
content.append('MimeType', attachment.type);
try {
let res = await axios.post(myUrl, content, new_options);
}catch(err){
console.warn(err);
}
我已经尝试过更新 FLIPPER_VERSION 或编辑 ReactNativeFlipper.java 之类的东西,但是我的项目中不存在这些东西,因为我使用的是旧版本的 react-native。我还尝试删除调试文件夹。
解决方案
想通了,问题是由错误的 MimeTypes 引起的。
推荐阅读
- yacc - 正确输入后无法继续解析
- python - 使用 Python3 / AttributeError 抓取网站:“NoneType”对象没有属性“文本”
- postgresql - 为什么 Postgresql 会为计数请求提供行数的答案?
- timezone - Azure 数据资源管理器中的时区感知查询
- node.js - 无法使用 PM2 创建节点脚本集群
- sails.js - 我在 SailsJs 上使用 waterline-orm 模型方法“.archive()”有一个“UsageError”
- javascript - 如果从顶部和底部滚动到视图中,则向元素添加不同的类
- c++11 - 为什么模板函数不能推导出大括号初始值设定项,但自动声明的变量可以?
- r - 如何在R中提取包含某些字符组合的单词
- lua - 脚本错误:@lscustoms/lscustoms.lua:355:'pairs' 的参数 #1 错误(应为表,结果为零)