react-native - 带有文件附件的表单帖子引发网络错误/React Native + react native 图像选择器
问题描述
我正在使用react-native-image-picker
获取图像详细信息并尝试在 https 后端服务器中上传。请求不成功,并引发网络错误。它没有与后端服务器建立连接。问题formdata
在于我发送的那个。header
如果我错过了,您能否提出建议和其他信息。
export const postImage = async state => {
let formData = new FormData();
formData.append('image', {
uri : state.photo.uri,
type: state.photo.type,
name : state.photo.fileName
});
const config = {
headers: {
'Content-Type': 'multipart/form-data',
Accept: "application/x-www-form-urlencoded",
'Accept': 'application/json'
},
};
try {
return $http.post('/image/save', formData, config)
.then(response => response)
.catch(error => error)
} catch(error) {
console.log(error)
}
}
环境: - Axios 版本 ^0.19.2 - 附加库版本 [React 16.11.0,React Native 0.62.1]
解决方案
鳍状肢存在问题,将其升级到 0.39.0 及更高版本即可
此处正在跟踪此问题:https ://github.com/facebook/react-native/issues/28551
修复:https ://github.com/facebook/flipper/issues/993#issuecomment-619823916
This should be fixed in version 0.39.0. To upgrade, edit android > gradle.properties
# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.39.0 // edit this manually
推荐阅读
- mysql - 如何修复“java.sql.SQLException:无法添加外键约束”。创建具有双主/外键关系的表时
- android - 如何支持 18.5:9 的宽高比?
- php - 如何在我的模态中显示来自 foreach 的数据?
- php - 基于关系 Laravel 5.8 和 Eloquent 更新数据库表
- c++ - 从 http 流(在 boost::beast 中)读取和写入的要求是什么?
- python - 如何在 Python 中使用 matplotlib 绘制数据?
- dimensional-modeling - DM 和层次结构 - 未来使用的维度
- python-3.x - ls -l 的打印输出 | 奇怪的东西
- c++ - 如何使用 CMake 使混合 C/C++ 项目工作
- angular - 使用条纹支付按钮时无法关闭角度材质对话框