public class DefaultPartHttpMessageReader extends LoggingCodecSupport implements HttpMessageReader<Part>
HttpMessageReader
for parsing "multipart/form-data"
requests to a stream of Part
s.
In default, non-streaming mode, this message reader stores the
contents of parts smaller than
maxInMemorySize
in memory, and parts larger
than that to a temporary file in
fileStorageDirectory
.
In streaming mode, the contents of the part is streamed directly from the parsed input buffer stream, and not stored in memory nor file.
This reader can be provided to MultipartHttpMessageReader
in order
to aggregate all parts into a Map.
logger
Constructor and Description |
---|
DefaultPartHttpMessageReader() |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this reader.
|
int |
getMaxInMemorySize()
Get the
configured maximum in-memory size. |
List<MediaType> |
getReadableMediaTypes()
Return the
MediaType 's that this reader supports. |
reactor.core.publisher.Flux<Part> |
read(ResolvableType elementType,
ReactiveHttpInputMessage message,
Map<String,Object> hints)
Read from the input message and encode to a stream of objects.
|
reactor.core.publisher.Mono<Part> |
readMono(ResolvableType elementType,
ReactiveHttpInputMessage message,
Map<String,Object> hints)
Read from the input message and encode to a single object.
|
void |
setBlockingOperationScheduler(reactor.core.scheduler.Scheduler blockingOperationScheduler)
Sets the Reactor
Scheduler to be used for creating files and
directories, and writing to files. |
void |
setFileStorageDirectory(Path fileStorageDirectory)
Sets the directory used to store parts larger than
maxInMemorySize . |
void |
setMaxDiskUsagePerPart(long maxDiskUsagePerPart)
Configure the maximum amount of disk space allowed for file parts.
|
void |
setMaxHeadersSize(int byteCount)
Configure the maximum amount of memory that is allowed per headers section of each part.
|
void |
setMaxInMemorySize(int maxInMemorySize)
Configure the maximum amount of memory allowed per part.
|
void |
setMaxParts(int maxParts)
Specify the maximum number of parts allowed in a given multipart request.
|
void |
setStreaming(boolean streaming)
When set to
true , the part content
is streamed directly from the parsed input buffer stream, and not stored
in memory nor file. |
isEnableLoggingRequestDetails, setEnableLoggingRequestDetails
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
read, readMono
public void setMaxHeadersSize(int byteCount)
byteCount
- the maximum amount of memory for headerspublic int getMaxInMemorySize()
configured
maximum in-memory size.public void setMaxInMemorySize(int maxInMemorySize)
DataBufferLimitException
.
By default this is set to 256K.
Note that this property is ignored when streaming is enabled.
maxInMemorySize
- the in-memory limit in bytes; if set to -1 the entire
contents will be stored in memorypublic void setMaxDiskUsagePerPart(long maxDiskUsagePerPart)
By default this is set to -1, meaning that there is no maximum.
Note that this property is ignored when
streaming is enabled, , or when
maxInMemorySize
is set to -1.
public void setMaxParts(int maxParts)
By default this is set to -1, meaning that there is no maximum.
public void setFileStorageDirectory(Path fileStorageDirectory) throws IOException
maxInMemorySize
. By default, a directory
named spring-webflux-multipart
is created under the system
temporary directory.
Note that this property is ignored when
streaming is enabled, or when
maxInMemorySize
is set to -1.
IOException
- if an I/O error occurs, or the parent directory
does not existpublic void setBlockingOperationScheduler(reactor.core.scheduler.Scheduler blockingOperationScheduler)
Scheduler
to be used for creating files and
directories, and writing to files. By default, a bounded scheduler is
created with default properties.
Note that this property is ignored when
streaming is enabled, or when
maxInMemorySize
is set to -1.
Schedulers.newBoundedElastic(int, int, java.lang.String)
public void setStreaming(boolean streaming)
true
, the part content
is streamed directly from the parsed input buffer stream, and not stored
in memory nor file.
When false
, parts are backed by
in-memory and/or file storage. Defaults to false
.
NOTE that with streaming enabled, the
Flux<Part>
that is produced by this message reader must be
consumed in the original order, i.e. the order of the HTTP message.
Additionally, the body contents must either
be completely consumed or canceled before moving to the next part.
Also note that enabling this property effectively ignores
maxInMemorySize
,
maxDiskUsagePerPart
,
fileStorageDirectory
, and
fileCreationScheduler
.
public List<MediaType> getReadableMediaTypes()
HttpMessageReader
MediaType
's that this reader supports.getReadableMediaTypes
in interface HttpMessageReader<Part>
public boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageReader
canRead
in interface HttpMessageReader<Part>
elementType
- the type of object to checkmediaType
- the media type for the read (possibly null
)true
if readable, false
otherwisepublic reactor.core.publisher.Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
HttpMessageReader
readMono
in interface HttpMessageReader<Part>
elementType
- the type of objects in the stream which must have been
previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the inputpublic reactor.core.publisher.Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
HttpMessageReader
read
in interface HttpMessageReader<Part>
elementType
- the type of objects in the stream which must have been
previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the input