public class MultipartHttpMessageWriter extends LoggingCodecSupport implements HttpMessageWriter<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.
FormHttpMessageWriter
Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET
THe default charset used by the writer.
|
logger
Constructor and Description |
---|
MultipartHttpMessageWriter()
Constructor with a default list of part writers (String and Resource).
|
MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
Constructor with explicit list of writers for serializing parts.
|
MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters,
HttpMessageWriter<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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
protected byte[] |
generateMultipartBoundary()
Generate a multipart boundary.
|
Charset |
getCharset()
Return the configured charset for part headers.
|
List<HttpMessageWriter<?>> |
getPartWriters()
Return the configured part writers.
|
List<MediaType> |
getWritableMediaTypes()
Return the
MediaType 's that this writer supports. |
void |
setCharset(Charset charset)
Set the character set to use for part headers such as
"Content-Disposition" (and its filename parameter).
|
reactor.core.publisher.Mono<Void> |
write(org.reactivestreams.Publisher<? extends MultiValueMap<String,?>> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage outputMessage,
Map<String,Object> hints)
Write an given stream of object to the output message.
|
isEnableLoggingRequestDetails, setEnableLoggingRequestDetails
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
write
public static final Charset DEFAULT_CHARSET
public MultipartHttpMessageWriter()
public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, @Nullable HttpMessageWriter<MultiValueMap<String,String>> formWriter)
partWriters
- the writers for serializing partsformWriter
- the fallback writer for form data, null
by defaultpublic List<HttpMessageWriter<?>> getPartWriters()
public void setCharset(Charset charset)
By default this is set to "UTF-8".
public Charset getCharset()
public List<MediaType> getWritableMediaTypes()
HttpMessageWriter
MediaType
's that this writer supports.getWritableMediaTypes
in interface HttpMessageWriter<MultiValueMap<String,?>>
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<MultiValueMap<String,?>>
elementType
- the type of object to checkmediaType
- the media type for the write (possibly null
)true
if writable, false
otherwisepublic reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends MultiValueMap<String,?>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String,Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<MultiValueMap<String,?>>
inputStream
- the objects to writeelementType
- 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 tohints
- additional information about how to encode and writeprotected byte[] generateMultipartBoundary()
By default delegates to MimeTypeUtils.generateMultipartBoundary()
.