public final class MultipartBodyBuilder
extends java.lang.Object
MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("form field", "form value"); Resource image = new ClassPathResource("image.jpg"); builder.part("image", image).header("Baz", "Qux"); MultiValueMap<String, HttpEntity<?>> multipartBody = builder.build(); // use multipartBody with RestTemplate or WebClient
Modifier and Type | Class and Description |
---|---|
static interface |
MultipartBodyBuilder.PartBuilder
Builder that allows for further customization of part headers.
|
static class |
MultipartBodyBuilder.PublisherEntity<T,P extends org.reactivestreams.Publisher<T>>
Specialization of
HttpEntity for use with a
Publisher -based body, for which we also need to keep track of
the element type. |
Constructor and Description |
---|
MultipartBodyBuilder()
Creates a new, empty instance of the
MultipartBodyBuilder . |
Modifier and Type | Method and Description |
---|---|
<T,P extends org.reactivestreams.Publisher<T>> |
asyncPart(java.lang.String name,
P publisher,
java.lang.Class<T> elementClass)
Add an asynchronous part with
Publisher -based content. |
<T,P extends org.reactivestreams.Publisher<T>> |
asyncPart(java.lang.String name,
P publisher,
ParameterizedTypeReference<T> typeReference)
Variant of
asyncPart(String, Publisher, Class) that accepts a
ParameterizedTypeReference for the element type, which allows
specifying generic type information. |
MultiValueMap<java.lang.String,HttpEntity<?>> |
build()
Return a
MultiValueMap with the configured parts. |
MultipartBodyBuilder.PartBuilder |
part(java.lang.String name,
java.lang.Object part)
Add a part from an Object.
|
MultipartBodyBuilder.PartBuilder |
part(java.lang.String name,
java.lang.Object part,
MediaType contentType)
Variant of
part(String, Object) that also accepts a MediaType
which is used to determine how to encode the part. |
public MultipartBodyBuilder()
MultipartBodyBuilder
.public MultipartBodyBuilder.PartBuilder part(java.lang.String name, java.lang.Object part)
name
- the name of the part to addpart
- the part datapublic MultipartBodyBuilder.PartBuilder part(java.lang.String name, java.lang.Object part, @Nullable MediaType contentType)
part(String, Object)
that also accepts a MediaType
which is used to determine how to encode the part.name
- the name of the part to addpart
- the part datacontentType
- the media type for the partpublic <T,P extends org.reactivestreams.Publisher<T>> MultipartBodyBuilder.PartBuilder asyncPart(java.lang.String name, P publisher, java.lang.Class<T> elementClass)
Publisher
-based content.name
- the name of the part to addpublisher
- the part contentselementClass
- the type of elements contained in the publisherpublic <T,P extends org.reactivestreams.Publisher<T>> MultipartBodyBuilder.PartBuilder asyncPart(java.lang.String name, P publisher, ParameterizedTypeReference<T> typeReference)
asyncPart(String, Publisher, Class)
that accepts a
ParameterizedTypeReference
for the element type, which allows
specifying generic type information.name
- the name of the part to addpublisher
- the part contentstypeReference
- the type of elements contained in the publisherpublic MultiValueMap<java.lang.String,HttpEntity<?>> build()
MultiValueMap
with the configured parts.