Affects: Spring Webmvc-5.2.7.RELEASE
Use case: I need to stream large files to another service via the WebClient class with a specific Content-Type (multipart/related). To build the request body I use the MultipartBodyBuilder. To create the BodyInserter for the WebClient I use the BodyInserters.fromMultipartData factory method.
Problem: Because the returned DefaultMultipartInserter from the BodyInserters.fromMultipartData factory method sets the Content-Type to multipart/form-data, I need to subclass MultipartInserter and copy almost the whole code from DefaultMultipartInserter only to change the content type. There is no easy way to override the standard content type while using BodyInserters.fromMultipartData.
Wish: Add the possibility to set the content type while using the aforementioned factory method.
Comment From: poutsma
You should be able to set the content type on the web client, like so:
WebClient webClient = ...
MultipartBodyBuilder builder = new MultipartBodyBuilder();
// use builder
MultiValueMap<String, HttpEntity<?>> parts = builder.build();
Mono<Void> result = webClient.post()
.contentType(MediaType.MULTIPART_RELATED)
.bodyValue(parts)
.retrieve()
.bodyToMono(Void.class);