Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse multipart servlet request #34441

Open
InglisDav opened this issue Feb 18, 2025 · 3 comments
Open

Failed to parse multipart servlet request #34441

InglisDav opened this issue Feb 18, 2025 · 3 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@InglisDav
Copy link

InglisDav commented Feb 18, 2025

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 18, 2025
@bclozel
Copy link
Member

bclozel commented Feb 18, 2025

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 ?

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue in: web Issues in web modules (web, webmvc, webflux, websocket) labels Feb 18, 2025
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Feb 19, 2025

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.

@spring-projects-issues
Copy link
Collaborator

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.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

4 participants