Skip to content

Failed to parse multipart servlet request #34441

@InglisDav

Description

@InglisDav

I am uploading a file from Angular using Java 17 with Spring Boot 3.2 as backend.
I noticed that when I updated Spring 2.x.x it shows me a multipart error. I don't know if the implementation with Angular changed for this type of request. The code I use is the following:

Angular17:

UploadFile(id, file:File): Observable<any[]> {

  url = 'http://localhost:8080/import/"+id+"'; 
  
  const formData: FormData = new FormData();
  formData.append('uploadFile', file, file.name);

  var headers: HttpHeaders = new HttpHeaders(); 
  headers = headers.set('Content-type', 'multipart/form-data');


 this.http.combineHeaders(headers);
  
 return this.http.post(url, formData, 'UploadFile');
}

Java17:

@RequestMapping(value = "/import", method = RequestMethod.POST)
public ResponseEntity<Object> FileUpload(@PathVariable(value = "id") String Id, @RequestParam("uploadFile") MultipartFile uploadFile)
            throws IOException {

        //Here is processing uploadFile.
}

Error:

{errCode: 4000, errMsg: "Failed to parse multipart servlet request"} errCode : 4000 errMsg : "Failed to parse multipart servlet request"

The library imported is import org.springframework.web.multipart.MultipartFile;
But it's very confusing because even though I don't have the file reading implementation, just by receiving the file as @RequestParam, I get the error.

Is it possible that something has changed for the new versions of Spring with Angular?

Thank you!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions