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!!

Comment From: bclozel

Can you reproduce the problem with a curl command instead of Angular? We are not aware of similar issues. Can you share a minimal sample application that reproduces the problem please ?

Comment From: rstoyanchev

Your controller method has an @PathVariable parameter, but the mapping path doesn't have a placeholder for it. It is possible the 400 relates to that?

I suggest getting more logging information on the server side to find the reason for the 400 and the actual exception.

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

You can vary the version of Spring and Angular independently to see which one causes the issue.

Generally, you need to investigate a bit further before opening an issue.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.