Skip to content

MultipartBodyBuilder requires parts to be named #30179

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

Closed
jakub-bochenski opened this issue Mar 23, 2023 · 5 comments
Closed

MultipartBodyBuilder requires parts to be named #30179

jakub-bochenski opened this issue Mar 23, 2023 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@jakub-bochenski
Copy link

Affects: 5.13.15

   public PartBuilder part(String name, Object part, @Nullable MediaType contentType) {
   	Assert.hasLength(name, "'name' must not be empty");

This is wrong and makes no sense for contents like multipart/mixed
Field names are only relevant for multipart/form-data

c.f. https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 23, 2023
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Mar 23, 2023
@sbrannen sbrannen changed the title MultipartBodyBuilder requries parts to be named MultipartBodyBuilder requires parts to be named Mar 23, 2023
@poutsma poutsma self-assigned this Mar 28, 2023
@poutsma
Copy link
Contributor

poutsma commented Mar 28, 2023

This is wrong and makes no sense for contents like multipart/mixed

Opening with a snarky comment like that does not help in getting attention drawn to your issue. If anything, the reverse is true.

MultipartBodyBuilder was not designed to be used for multipart/mixed, but for multipart/form-data where each part gets a Content-Disposition header with the part name. Given this context, I would argue that the method signature is correct and makes a lot of sense.

I see that the Javadoc of MultipartBodyBuilder can be improved to make this limitation clearer, and I will do so.

@poutsma poutsma closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2023
@poutsma poutsma added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 28, 2023
poutsma added a commit that referenced this issue Mar 28, 2023
This commit improves the Javadoc of MultipartBodyBuilder, to make it
clear that it is intended for multipart/form-data.

See gh-30179
@jakub-bochenski
Copy link
Author

jakub-bochenski commented Mar 28, 2023

Oh, nice, so WebClient now officially doesn't support multipart/mixed

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 28, 2023

There is some additional context on this.

Our multipart support has evolved historically from multipart form data requests, so it is rooted in that. We added "multipart/mixed" and "multipart/related" as supported media types to the codecs and message converters with #23159 and #23209, but in retrospect that was inadequate.

In any case, this would be a deeper change, most likely not involving MultipartBodyBuilder at all, since that prepares a MultiValueMap, and hence assumes parts have names.

It would help if you provide a bit more context around your case. Do you need both client and server support, or do you make requests to a 3rd party API? Considering the Servlet API also assumes parts have names, there can be more challenges.

@jakub-bochenski
Copy link
Author

jakub-bochenski commented Mar 28, 2023

I'm using a 3rd party API that is receiving and responding with multipart/mixed. So I'm interested just in client support.

I'm able to send multipart/mixed using MultiValueMap just by setting all the names to empty string.
But MultiValueMap doesn't support "reactive" elements the way MultipartBodyBuilder does.

As for reading the response it seems RestTemplate can only write multipart/mixed, not read it.
For WebClient the best I could come up with is

.retrieve()
                .toEntityFlux((inputMessage, context) ->
                        partReader
                                .read(ResolvableType.forType(byte[].class), inputMessage, context))

but it's inconvenient to the have to deal with raw bytes from DataBuffer for each part.

Also I don't see how would it handle reading multipart nested in multipart --it's a real-world scenario

@poutsma
Copy link
Contributor

poutsma commented Mar 29, 2023

I have created #30230 to see how much interest there is in the community for Spring to have proper multipart/mixed support.

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: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants