【发布时间】:2020-11-16 09:35:49
【问题描述】:
我有这个数据 来自 react-native-image-picker
data: "/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2Qtan" => 90kb
fileName: "77677.jpg"
fileSize: 67542
height: 600
isVertical: true
originalRotation: 0
path: "/storage/emulated/0/Download/77677.jpg"
type: "image/jpeg"
uri: "content://media/external/images/media/18584"
width: 399
__proto__: Object
我尝试将此数据设置为对象类型#FromData 以上传#img
var binaryDataInBase64 = new FormData();
binaryDataInBase64.append('file', {
// data: response.data,
uri: 'file://' + response.uri,
name: 'MMM.jpg',
type: response.type
})
console.log('=======================>', binaryDataInBase64)
axios.post(
'https://danskeclouddemo.com/api/file',
{ file: binaryDataInBase64 },
{ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/form-data' } }
).then(res => {
console.log(res)
}).catch(error => {
console.log(error)
})
这是后端邮递员工作良好Postman collection
//======================= //======================= 编辑
有人说0.61.5之后的react native版本的问题 在这个链接issues
【问题讨论】:
-
请勿发布图片。邮政编码/文字。
-
好的,我会编辑那个,
-
另外,你正在做
console.log(error),尝试做console.log(error.response); -
错误更清楚了
-
但还是不行
标签: reactjs typescript react-native axios react-native-android