类 MultipartBodyBuilder
java.lang.Object
cn.taketoday.http.client.MultipartBodyBuilder
Prepare the body of a multipart request, resulting in a
MultiValueMap<String, HttpEntity>. Parts may be concrete values or
via asynchronous types such as Reactor Mono, Flux, and
others registered in the
ReactiveAdapterRegistry.
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("...")
.body(multipartBody)
.retrieve()
.bodyToMono(Void.class)
- 从以下版本开始:
- 4.0 2021/11/5 23:00
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classstatic interfaceBuilder that allows for further customization of part headers.(专用程序包) static final classMultipartBodyBuilder.PublisherEntity<T,P extends org.reactivestreams.Publisher<T>> Specialization ofHttpEntityfor use with aPublisher-based body, for which we also need to keep track of the element type.private static classMultipartBodyBuilder.PublisherPartBuilder<S,P extends org.reactivestreams.Publisher<S>> -
字段概要
字段修饰符和类型字段说明private final cn.taketoday.util.DefaultMultiValueMap<String,MultipartBodyBuilder.DefaultPartBuilder> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明<T,P extends org.reactivestreams.Publisher<T>>
MultipartBodyBuilder.PartBuilderVariant ofasyncPart(String, Publisher, Class)with aParameterizedTypeReferencefor the element type information.<T,P extends org.reactivestreams.Publisher<T>>
MultipartBodyBuilder.PartBuilderAdd a part fromPublishercontent.cn.taketoday.util.MultiValueMap<String,HttpEntity<?>> build()Return aMultiValueMapwith the configured parts.Add a part where the Object may be: String -- form fieldResource-- file part Object -- content to be encoded (e.g. to JSON)HttpEntity-- part content and headers although generally it's easier to add headers through the returned builderPart-- a part from a server requestVariant ofpart(String, Object)that also accepts a MediaType.
-
字段详细资料
-
parts
private final cn.taketoday.util.DefaultMultiValueMap<String,MultipartBodyBuilder.DefaultPartBuilder> parts
-
-
构造器详细资料
-
MultipartBodyBuilder
public MultipartBodyBuilder()
-
-
方法详细资料
-
part
Add a part where the Object may be:- String -- form field
Resource-- file part- Object -- content to be encoded (e.g. to JSON)
HttpEntity-- part content and headers although generally it's easier to add headers through the returned builderPart-- a part from a server request
- 参数:
name- the name of the part to addpart- the part data- 返回:
- builder that allows for further customization of part headers
-
part
public MultipartBodyBuilder.PartBuilder part(String name, Object part, @Nullable MediaType contentType) Variant ofpart(String, Object)that also accepts a MediaType.- 参数:
name- the name of the part to addpart- the part datacontentType- the media type to help with encoding the part- 返回:
- builder that allows for further customization of part headers
-
asyncPart
public <T,P extends org.reactivestreams.Publisher<T>> MultipartBodyBuilder.PartBuilder asyncPart(String name, P publisher, Class<T> elementClass) Add a part fromPublishercontent.- 参数:
name- the name of the part to addpublisher- a Publisher of content for the partelementClass- the type of elements contained in the publisher- 返回:
- builder that allows for further customization of part headers
-
asyncPart
public <T,P extends org.reactivestreams.Publisher<T>> MultipartBodyBuilder.PartBuilder asyncPart(String name, P publisher, cn.taketoday.core.ParameterizedTypeReference<T> typeReference) Variant ofasyncPart(String, Publisher, Class)with aParameterizedTypeReferencefor the element type information.- 参数:
name- the name of the part to addpublisher- the part contentstypeReference- the type of elements contained in the publisher- 返回:
- builder that allows for further customization of part headers
-
build
Return aMultiValueMapwith the configured parts.
-