Reactjs Can';t将多部分/表单数据从React发送到Spring

Reactjs Can';t将多部分/表单数据从React发送到Spring,reactjs,rest,spring-boot,Reactjs,Rest,Spring Boot,我想从React上传文件并将其发送到springboot。 我试图从React FormData发布,它将包含文件名和XML文件的键值对。因此,当我尝试将FormData发布到我的后端Springboot时,它会返回: .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application

我想从React上传文件并将其发送到springboot。 我试图从React FormData发布,它将包含文件名和XML文件的键值对。因此,当我尝试将FormData发布到我的后端Springboot时,它会返回:

.w.s.m.s.DefaultHandlerExceptionResolver : Resolved 
[org.springframework.web.HttpMediaTypeNotSupportedException: 
Content type 'application/json;charset=UTF-8' not supported]
这是我的代码:

handleSubmit = (e) => {
e.preventDefault();
console.log(this.state.file[0].name);
const formData = new FormData();
var i = this.state.file.length;
console.log(i);
for (var j = 0; j < i; j++) {
    formData.append(this.state.file[j].name, this.state.file[j])
}
for (var pair of formData.entries()) {
    console.log(pair[0] + ',' + pair[1]);
}

Axios.post('http://localhost:8080/upload', {
    file:formData
  })
  .then(response=>{
      console.log(response)
  })
  ;
我已经尝试在Axios post请求的头中指定多部分/表单数据,但它似乎不起作用。 是我的请求有问题还是我的控制器有问题?
如果你有任何想法,请告诉我,我已经用了几个小时的时间试图解决这个问题。

尝试
标题:{'Content-Type':undefined},
在发送请求时。还要确保表单中有
enctype=“multipart/form data”


-能否尝试将控制器更改为如下所示,而不是@RequestParam

@RequestPart("file") MultipartFile file
  • 现在也试着上传一个文件,让我们看看它是如何运行的

这两件事我都做过。还有其他建议吗?
@RequestPart("file") MultipartFile file