POST文件multipart/form-data(JavaScript)时出错
问题描述:
每次尝试将数据发布到API时都出现错误。 请求:POST文件multipart/form-data(JavaScript)时出错
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);
});
}
错误:profile_image不能为空(422)。
但它不是空白!
我该怎么办错了吗?