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

Add explicit support for multipart/mixed in FormHttpMessageConverter #23209

Closed
2 tasks done
sbrannen opened this issue Jun 28, 2019 · 0 comments
Closed
2 tasks done

Add explicit support for multipart/mixed in FormHttpMessageConverter #23209

sbrannen opened this issue Jun 28, 2019 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Jun 28, 2019

Overview

gh-23159 added support for multipart/* media types in FormHttpMessageConverter, but users must still manually register multipart/mixed as a supported media type in order to POST multipart data with that content type.

For example, something similar to the following code is required to get it work.

MediaType multipartMixed = new MediaType("multipart", "mixed");

restTemplate.getMessageConverters().stream()
    .filter(FormHttpMessageConverter.class::isInstance)
    .map(FormHttpMessageConverter.class::cast)
    .findFirst()
    .orElseThrow(() ->
        new IllegalStateException("Failed to find FormHttpMessageConverter"))
    .addSupportedMediaTypes(multipartMixed);

MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("field 1", "value 1");
parts.add("file", new ClassPathResource("myFile.jpg"));

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(multipartMixed);
HttpEntity<MultiValueMap<String, Object>> requestEntity =
    new HttpEntity<>(parts, requestHeaders);

restTemplate.postForLocation("example.com/myFileUpload", requestEntity);

Since multipart/mixed is rather common in REST scenarios, it would be nice if users could forgo the steps required to manually register it as a supported media type.

Deliverables

  • Introduce a multipart/mixed constant in MediaType.
  • Add explicit support for multipart/mixed in FormHttpMessageConverter.
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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant