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

PartFile name lost when building a MultiPart #27007

Closed
AbdelHedhili opened this issue May 31, 2021 · 0 comments
Closed

PartFile name lost when building a MultiPart #27007

AbdelHedhili opened this issue May 31, 2021 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@AbdelHedhili
Copy link

AbdelHedhili commented May 31, 2021

As requested here is the new issue @poutsma

My server receive a multipart, take the FilePart from the incoming request and rename it in the outgoing request. Something like that:

  public Mono<ResponseEntity<SomeEntityId>> upload(
      @RequestBody Mono<MultiValueMap<String, Part>> parts) {
    return someServiceClient.upload(parts.map(m -> (FilePart) m.get("foo").get(0));    //here I take the foo part 

  }

  public Mono<ResponseEntity<SomeEntityId>> upload(
      Mono<MultiValueMap<String, Part>> partsMono) {
    return multipartFile.flatMap(file -> {
            MultipartBodyBuilder multipartBodyBuilder = new MultipartBodyBuilder();
            multipartBodyBuilder.part("bar", file); //here I rename it to bar
            return webClient.post()
                    .uri("uri")
                    .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA.toString())
                    .body(BodyInserters.fromMultipartData(multipartBodyBuilder.build()))
        });
    }

I came across this issue when upgrading my spring version : when I do this, in the outgoing request, the part that I wanted to rename "bar" is still named "foo". It worked in spring 5.2.8 (it renamed the part) but in 5.3.6 the file is not renamed anymore.
I think it's related to this commit e537844 and to the issue #26410

Do you have any advice ?
Thanks.

@poutsma poutsma self-assigned this May 31, 2021
@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression labels May 31, 2021
@poutsma poutsma added this to the 5.3.8 milestone May 31, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Make sure that we use the parameter name in MultipartBodyBuilder::part
when adding a Part, instead of using the name specified in the
'Content-Disposition' header that might have been in the part's headers.

Closes spring-projectsgh-27007
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) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants