MultiValueMap<String, HttpEntity>. Parts may be concrete values or
via asynchronous types such as Reactor Mono, Flux, and
others registered in the
ReactiveAdapterRegistry.
This builder is intended to POST multipart/form-data using the reactive
WebClient.
For multipart requests with the RestTemplate, simply create and
populate a MultiValueMap<String, HttpEntity> as shown in the Javadoc for
FormHttpMessageConverter
and in the
reference docs.
Below are examples of using this builder:
// Add form field
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("form field", "form value").header("foo", "bar");
// Add file part
Resource image = new ClassPathResource("image.jpg");
builder.part("image", image).header("foo", "bar");
// Add content (e.g. JSON)
Account account = ...
builder.part("account", account).header("foo", "bar");
// Add content from Publisher
Mono<Account> accountMono = ...
builder.asyncPart("account", accountMono).header("foo", "bar");
// Build and use
MultiValueMap<String, HttpEntity<?>> multipartBody = builder.build();
Mono<Void> result = webClient.post()
.uri("...")
.bodyValue(multipartBody)
.retrieve()
.bodyToMono(Void.class)
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static interface | MultipartBodyBuilder.PartBuilder
Builder that allows for further customization of part headers. |
| pack-priv static class | MultipartBodyBuilder.PublisherEntity<
the type contained in the publisher T, the publisher P extends PublisherSpecialization of |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final LinkedMultiValueMap |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public <T, P extends Publisher | |
| public <T, P extends Publisher | Returns: builder that allows for further customization of part headersthe name of the part to add name, P the part contents publisher, ParameterizedTypeReference<T> the type of elements contained in the publisher typeReference)Variant of |
| public MultiValueMap | |
| public MultipartBodyBuilder. | Returns: builder that allows for further customization of part headersthe name of the part to add name, Object the part data part)Add a part where the Object may be:
|
| public MultipartBodyBuilder. | Returns: builder that allows for further customization of part headersthe name of the part to add name, Object the part data part, MediaType the media type to help with encoding the part contentType)Variant of |
| parts | back to summary |
|---|---|
| private final LinkedMultiValueMap<String, MultipartBodyBuilder. | |
| MultipartBodyBuilder | back to summary |
|---|---|
| public MultipartBodyBuilder() Creates a new, empty instance of the | |
| asyncPart | back to summary |
|---|---|
| public <T, P extends Publisher Add a part from
| |
| asyncPart | back to summary |
|---|---|
| public <T, P extends Publisher Variant of
| |
| build | back to summary |
|---|---|
| public MultiValueMap Return a | |
| part | back to summary |
|---|---|
| public MultipartBodyBuilder. Add a part where the Object may be:
| |
| part | back to summary |
|---|---|
| public MultipartBodyBuilder. Variant of
| |
| Modifier and Type | Field and Description |
|---|---|
| protected final Object | |
| protected HttpHeaders | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public |
| body | back to summary |
|---|---|
| protected final Object body
| |
| headers | back to summary |
|---|---|
| protected HttpHeaders headers
| |
| name | back to summary |
|---|---|
| private final String name | |
| DefaultPartBuilder | back to summary |
|---|---|
| public DefaultPartBuilder(String name, HttpHeaders headers, Object body) | |
| build | back to summary |
|---|---|
| public HttpEntity | |
| contentType | back to summary |
|---|---|
| public MultipartBodyBuilder. Implements org. Doc from org. Set the media type of the part. | |
| filename | back to summary |
|---|---|
| public MultipartBodyBuilder. Implements org. Doc from org. Set the filename parameter for a file part. This should not be
necessary with | |
| header | back to summary |
|---|---|
| public MultipartBodyBuilder. Implements org. Doc from org. Add part header values.
| |
| headers | back to summary |
|---|---|
| public MultipartBodyBuilder. Implements org. Doc from org. Manipulate the part headers through the given consumer.
| |
| initHeadersIfNecessary | back to summary |
|---|---|
| private HttpHeaders initHeadersIfNecessary() | |
| Modifier and Type | Method and Description |
|---|---|
| public MultipartBodyBuilder. | |
| public MultipartBodyBuilder. | |
| public MultipartBodyBuilder. | |
| public MultipartBodyBuilder. | Returns: this builderconsumer to manipulate the part headers with headersConsumer)Manipulate the part headers through the given consumer. |
| contentType | back to summary |
|---|---|
| public MultipartBodyBuilder. Set the media type of the part.
| |
| filename | back to summary |
|---|---|
| public MultipartBodyBuilder. Set the filename parameter for a file part. This should not be
necessary with
| |
| header | back to summary |
|---|---|
| public MultipartBodyBuilder. Add part header values.
| |
| headers | back to summary |
|---|---|
| public MultipartBodyBuilder. Manipulate the part headers through the given consumer.
| |
HttpEntity for use with a
Publisher-based body, for which we also need to keep track of
the element type.
| Modifier and Type | Field and Description |
|---|---|
| private final ResolvableType |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public ResolvableType | getResolvableType()
Implements org. Publisher body.
|
| resolvableType | back to summary |
|---|---|
| private final ResolvableType resolvableType | |
| PublisherEntity | back to summary |
|---|---|
| pack-priv PublisherEntity(MultiValueMap<String, String> headers, P publisher, ResolvableType resolvableType) | |
| getResolvableType | back to summary |
|---|---|
| public ResolvableType getResolvableType() Implements org. Return the element type for the | |
| Modifier and Type | Field and Description |
|---|---|
| private final ResolvableType |
| Access | Constructor and Description |
|---|---|
| public | |
| public | PublisherPartBuilder(String name, HttpHeaders headers, P body, ParameterizedTypeReference<S> typeRef)
|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public HttpEntity |
| resolvableType | back to summary |
|---|---|
| private final ResolvableType resolvableType | |
| PublisherPartBuilder | back to summary |
|---|---|
| public PublisherPartBuilder(String name, HttpHeaders headers, P body, Class<S> elementClass) | |
| PublisherPartBuilder | back to summary |
|---|---|
| public PublisherPartBuilder(String name, HttpHeaders headers, P body, ParameterizedTypeReference<S> typeRef) | |
| PublisherPartBuilder | back to summary |
|---|---|
| public PublisherPartBuilder(String name, MultipartBodyBuilder. | |
| build | back to summary |
|---|---|
| public HttpEntity Overrides org.
| |