类 MultipartHttpMessageWriter

所有已实现的接口:
HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,?>>

public class MultipartHttpMessageWriter extends MultipartWriterSupport implements HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,?>>
HttpMessageWriter for writing a MultiValueMap<String, ?> as multipart form data, i.e. "multipart/form-data", to the body of a request.

The serialization of individual parts is delegated to other writers. By default only String and Resource parts are supported but you can configure others through a constructor argument.

This writer can be configured with a FormHttpMessageWriter to delegate to. It is the preferred way of supporting both form data and multipart data (as opposed to registering each writer separately) so that when the MediaType is not specified and generics are not present on the target element type, we can inspect the values in the actual map and decide whether to write plain form data (String values only) or otherwise.

从以下版本开始:
4.0
作者:
Sebastien Deleuze, Rossen Stoyanchev
另请参阅:
  • 字段详细资料

  • 构造器详细资料

    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter()
      Constructor with a default list of part writers (String and Resource).
    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
      Constructor with explicit list of writers for serializing parts.
    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, @Nullable HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,String>> formWriter)
      Constructor with explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.
      参数:
      partWriters - the writers for serializing parts
      formWriter - the fallback writer for form data, null by default
    • MultipartHttpMessageWriter

      public MultipartHttpMessageWriter(Supplier<List<HttpMessageWriter<?>>> partWritersSupplier, @Nullable HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,String>> formWriter)
      Constructor with a supplier for an explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.
      参数:
      partWritersSupplier - the supplier for writers for serializing parts
      formWriter - the fallback writer for form data, null by default
  • 方法详细资料

    • initMediaTypes

      private static List<MediaType> initMediaTypes(@Nullable HttpMessageWriter<?> formWriter)
    • getPartWriters

      public List<HttpMessageWriter<?>> getPartWriters()
      Return the configured part writers.
      从以下版本开始:
      4.0
    • getFormWriter

      @Nullable public HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,String>> getFormWriter()
      Return the configured form writer.
    • canWrite

      public boolean canWrite(cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType)
      从接口复制的说明: HttpMessageWriter
      Whether the given object type is supported by this writer.
      指定者:
      canWrite 在接口中 HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,?>>
      参数:
      elementType - the type of object to check
      mediaType - the media type for the write (possibly null)
      返回:
      true if writable, false otherwise
    • write

      public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends cn.taketoday.util.MultiValueMap<String,?>> inputStream, cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String,Object> hints)
      从接口复制的说明: HttpMessageWriter
      Write an given stream of object to the output message.
      指定者:
      write 在接口中 HttpMessageWriter<cn.taketoday.util.MultiValueMap<String,?>>
      参数:
      inputStream - the objects to write
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
      mediaType - the content type for the write (possibly null to indicate that the default content type of the writer must be used)
      outputMessage - the message to write to
      hints - additional information about how to encode and write
      返回:
      indicates completion or error
    • isMultipart

      private boolean isMultipart(cn.taketoday.util.MultiValueMap<String,?> map, @Nullable MediaType contentType)
    • writeMultipart

      private reactor.core.publisher.Mono<Void> writeMultipart(cn.taketoday.util.MultiValueMap<String,?> map, ReactiveHttpOutputMessage outputMessage, @Nullable MediaType mediaType, Map<String,Object> hints)
    • encodePartValues

      private reactor.core.publisher.Flux<cn.taketoday.core.io.buffer.DataBuffer> encodePartValues(byte[] boundary, String name, List<?> values, cn.taketoday.core.io.buffer.DataBufferFactory bufferFactory)
    • encodePart

      private <T> reactor.core.publisher.Flux<cn.taketoday.core.io.buffer.DataBuffer> encodePart(byte[] boundary, String name, T value, cn.taketoday.core.io.buffer.DataBufferFactory factory)