我正在向服务器发出POST请求,以上传图像并使用react-native中的axios发送formdata。我收到“网络错误”。我也尝试获取但无济于事。使用反应本机图像选择器库选择图像。在邮递员api中工作正常
formData.append('title', Title);
formData.append('class_id', selectClass._id)
formData.append('subject_id', checkSelected)
formData.append('teacher_id', userId)
formData.append('description', lecture);
formData.append('type', 'image');
var arr=[];
arr.push(imageSource)
arr.map((file,index)=>{
formData.append('file',{
uri:file.path,
type:file.type,
name:file.name
})
})
axios({
method: 'post',
url: URL + 'admin/assignment/create',
data: data,
headers: {
"content-type": "multipart/form-data",
'x-auth-token': token,
},
})
.then(function (response) {
//handle success
console.log('axios assigment post',response);
})
.catch(function (response) {
//handle error
console.log('axios assigment post',response);
});
“ react-native”:“ 0.62.1”,“ react”:“ 16.11.0”,“ axios”:“ ^ 0.19.2”,
怪异的解决方案,我必须在android-> app-> source-> debug中删除调试文件夹
然后重新启动应用程序,即可解决我的问题。我认为这是缓存问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句