使用邮寄表格数据上传Axios图像始终会返回网络错误

时间:2019-10-07 07:46:44

标签: android react-native axios

在使用axios运行本机的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在邮递员上正常工作。我可以上传图片。我得到了回应{     “成功”:是 }

在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)

1 个答案:

答案 0 :(得分:0)

您的过往身体真实,请检查您的互联网。