Axios post 调用返回 400 状态码

时间:2021-05-26 14:58:52

标签: rest express axios

当我尝试点击 post call 并将输入文件作为 formdata 发送时,我正面临 400 状态代码,如下所示。任何人都可以帮我解决这个问题吗?

const file = req['file'].buffer.toString('base64');
 const formData = new FormData();
 formData.append('file', file);

         axios.post('http://localhost:8082/postFile',formData,
         {
            headers: {
            'Content-Type':'multipart/form-data; boundary='+timestamp
            }
        })
          .then((response) => {
            console.log("RESPONSE RECEIVED: ", response);
      
          })
          .catch((err) => {
            console.log("AXIOS ERROR: ", err);

          });

错误:

data: {
      timestamp: '2021-05-26T14:54:37.560+0000',
       status: 400,
       error: 'Bad Request',
       message: "Required request part 'file' is not present",
       path: '/postFile'
     }

0 个答案:

没有答案
相关问题