在使用 axios 运行 react native 的 android 上上传图像时出现问题。我已经对此进行了很多研究,并且在过去的 3 天里尝试了很多东西,但还没有解决方案。 这似乎是android上一个非常普遍的问题。任何帮助表示赞赏。
let url = "myURL will be here"
let uploadBody = new FormData()
uploadBody.append('photos',{uri:this.state.coverImage[0].uri,type: 'image/jpeg',
name: 'coverimage'})
axios.post(url,
{
method: "POST",
body: uploadBody,
headers : {
"Content-Type":"application/x-www-form-urlencoded"
}
}).then((resp) => {
console.log(resp);
}).catch(err => {
console.log(err);
});
该 API 在 Postman 上运行良好。我可以上传图片。我得到回应{ “成功”:真实
在android上获取这个错误
Error: Network Error
at createError (createError.js:15)
at XMLHttpRequest.handleError (xhr.js:88)
at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:388)
at XMLHttpRequest.js:501
at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
at MessageQueue.__callFunction (MessageQueue.js:395)
at MessageQueue.js:106
at MessageQueue.__guard (MessageQueue.js:343)
最佳答案
你路过的 body 是真的检查你的互联网网络。
关于android - axios图片上传使用post form数据总是返回网络错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58265367/