繁体   English   中英

POST文件多部分/表单数据(JavaScript)时出错

[英]Error when POST file multipart/form-data (JavaScript)

每次尝试将数据发布到API时,都会出现错误。 请求:

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

但这不是空白!

请求有效负载 在此处输入图片说明

我做错了什么?

在GutHub解决: https : //github.com/github/fetch/issues/505

我只需要离开Header而无需手动指向任何Content-Type

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM