[英]Error when POST file multipart/form-data (JavaScript)
I got an error every time when trying to POST data to the API. 每次尝试将数据发布到API时,都会出现错误。 Request:
请求:
changeUserAvatar(authParam, file) {
let formData = new FormData();
//file is actually new FileReader.readAsDataURL(myId.files[0]);
formData.append('profile_image', file);
fetch(BASE_URL + 'profile-image', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': authParam
},
body: formData
}).then((response) => {
return response.json();
}).then((response) => {
debugger;
}).catch((error) => {
console.error(error);
});
}
Error : profile_image can not be blank (422). 错误 :profile_image不能为空(422)。
But it's not blank! 但这不是空白!
What do I do wrong? 我做错了什么?
Solved at GutHub: https://github.com/github/fetch/issues/505 在GutHub解决: https : //github.com/github/fetch/issues/505
I just had to leave Header
without pointing any Content-Type
manually. 我只需要离开
Header
而无需手动指向任何Content-Type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.