首页 > 解决方案 > 反应:Axios 发布一个带有 blob 文件的数组,但发生 415 错误

问题描述

我正在尝试将包含多个 blob 文件的数组从 React 上传到 springboot 后端服务器。数组是这样的 [blob, blob, blob, blob, ...]

我应该制作几个网络摄像头捕获图像并一次请求 Axios Post,所以我用 blob 制作了那个数组。但是发生了415错误。

下面是 react.js 代码

const interviewSubmit = () =>{
    var formdata = new FormData();
    formdata.append("file", captureImgBlob)
    axios({
      url:baseURL + "test/interview/face",
      method:'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      body:formdata,
    })
      .then((res)=>{
        console.log(res)
      })
      .catch((err)=>{
        console.log(formdata)
      })
  }

数组是这样的

和springboot代码

@PostMapping(value = "/test/interview/face" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<EvalEmotionRes> getInput(@RequestPart List<MultipartFile> image) throws IOException {
    return ResponseEntity.ok().body(emotionService.emotionResult(image));
}

这是错误消息 错误消息 如何使此代码正常工作?

标签: reactjsspring-bootblob

解决方案


推荐阅读