Regarding the solution to the problem of using the vue component van-uploader to upload images and the backend receives the error Current request is not a multipart request

Problems encountered when uploading images:

        The backend receives this:

                @RequestParam MultipartFile file

                There is no problem no matter how you look at it, but an error 400 is reported saying that the current request is not a multi-part request. It is not until I open the front-end code that I know the problem.

        The front-end code is written like this:

changeType(val){
  
  this.post( val,this.$sParam.photoUpload).then(response=>

        Well, it was transmitted directly without processing. No wonder the background reported an error. If you know the problem, you can solve it next.

The correct format is as follows:

        You have to format it into formData, so there will be no problem in uploading it.

changeType(val){
  const data = new FormData();
  data.append("file", val.file); //上传的是 File 对象
  this.post( data,this.$sParam.photoUpload).then(response=>

    avoid pits avoid pits

Guess you like

Origin blog.csdn.net/zjb1697922408/article/details/127497022