文件上传报错:Current request is not a multipart request

时间:2022-10-22 19:54:46

  "error": "Internal Server Error",
  "exception": "org.springframework.web.multipart.MultipartException",
  "message": "Current request is not a multipart request", "path": "/upload"

错误原因:Headers填写错误,估计是之前选错了x-www-form-urlencoded

文件上传报错:Current request is not a multipart request

由于上传文件用的Content-Type应该是multipart/form-data,修改之后依然报错。

  "error": "Internal Server Error",
  "exception": "org.springframework.web.multipart.MultipartException",
  "message": "Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found",
  "path": "/upload"

解析之后发现Content-Type实际用的是text/plain。但是这么输入依然报相同错误。

多次试验之后发现,Content-Type无论选择什么,都会报错。正确的做法是删除Content-Type就行了。