Class DefaultPartHttpMessageReader
- All Implemented Interfaces:
- HttpMessageReader<Part>
HttpMessageReader for parsing "multipart/form-data"
 requests to a stream of Parts.
 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.
 
This reader can be provided to MultipartHttpMessageReader in order
 to aggregate all parts into a Map.
- Since:
- 5.3
- Author:
- Arjen Poutsma
- 
Field SummaryFields inherited from class org.springframework.http.codec.LoggingCodecSupportlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanRead(ResolvableType elementType, MediaType mediaType) Whether the given object type is supported by this reader.intGet theconfiguredmaximum in-memory size.Return the list of media types supported by this reader.reactor.core.publisher.Flux<Part>read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Read from the input message and decode 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 decode to a single object.voidsetBlockingOperationScheduler(reactor.core.scheduler.Scheduler blockingOperationScheduler) Set the ReactorSchedulerto be used for creating files and directories, and writing to files.voidsetFileStorageDirectory(Path fileStorageDirectory) Set the directory used to store parts larger thanmaxInMemorySize.voidsetHeadersCharset(Charset headersCharset) Set the character set used to decode headers.voidsetMaxDiskUsagePerPart(long maxDiskUsagePerPart) Configure the maximum amount of disk space allowed for file parts.voidsetMaxHeadersSize(int byteCount) Configure the maximum amount of memory that is allowed per headers section of each part.voidsetMaxInMemorySize(int maxInMemorySize) Configure the maximum amount of memory allowed per part.voidsetMaxParts(int maxParts) Specify the maximum number of parts allowed in a given multipart request.voidsetStreaming(boolean streaming) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class org.springframework.http.codec.LoggingCodecSupportisEnableLoggingRequestDetails, setEnableLoggingRequestDetailsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.codec.HttpMessageReadergetReadableMediaTypes, read, readMono
- 
Constructor Details- 
DefaultPartHttpMessageReaderpublic DefaultPartHttpMessageReader()
 
- 
- 
Method Details- 
setMaxHeadersSizepublic void setMaxHeadersSize(int byteCount) Configure the maximum amount of memory that is allowed per headers section of each part. When the limit- Parameters:
- byteCount- the maximum amount of memory for headers
 
- 
getMaxInMemorySizepublic int getMaxInMemorySize()Get theconfiguredmaximum in-memory size.
- 
setMaxInMemorySizepublic void setMaxInMemorySize(int maxInMemorySize) Configure the maximum amount of memory allowed per part. When the limit is exceeded:- file parts are written to a temporary file.
- non-file parts are rejected with DataBufferLimitException.
 By default this is set to 256K. Note that this property is ignored when streaming is enabled. - Parameters:
- maxInMemorySize- the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory
 
- 
setMaxDiskUsagePerPartpublic void setMaxDiskUsagePerPart(long maxDiskUsagePerPart) Configure the maximum amount of disk space allowed for file parts.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 maxInMemorySizeis set to -1.
- 
setMaxPartspublic void setMaxParts(int maxParts) Specify the maximum number of parts allowed in a given multipart request.By default this is set to -1, meaning that there is no maximum. 
- 
setFileStorageDirectorySet the directory used to store parts larger thanmaxInMemorySize. By default, a directory namedspring-webflux-multipartis created under the system temporary directory.Note that this property is ignored when streaming is enabled, or when maxInMemorySizeis set to -1.- Throws:
- IOException- if an I/O error occurs, or the parent directory does not exist
 
- 
setBlockingOperationSchedulerpublic void setBlockingOperationScheduler(reactor.core.scheduler.Scheduler blockingOperationScheduler) Set the ReactorSchedulerto be used for creating files and directories, and writing to files. By default,Schedulers.boundedElastic()is used, but this property allows for changing it to an externally managed scheduler.Note that this property is ignored when streaming is enabled, or when maxInMemorySizeis set to -1.- See Also:
- 
- Schedulers.boundedElastic()
 
 
- 
setStreamingDeprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofPartEventandPartEventHttpMessageReaderWhen set totrue, the part content is streamed directly from the parsed input buffer stream, and not stored in memory nor file. Whenfalse, parts are backed by in-memory and/or file storage. Defaults tofalse.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, andfileCreationScheduler.
- 
setHeadersCharsetSet the character set used to decode headers. Defaults to UTF-8 as per RFC 7578.- Parameters:
- headersCharset- the charset to use for decoding headers
- Since:
- 5.3.6
- See Also:
 
- 
getReadableMediaTypesDescription copied from interface:HttpMessageReaderReturn the list of media types supported by this reader. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, useHttpMessageReader.getReadableMediaTypes(ResolvableType)for a more precise list.- Specified by:
- getReadableMediaTypesin interface- HttpMessageReader<Part>
- Returns:
- the general list of supported media types
 
- 
canReadDescription copied from interface:HttpMessageReaderWhether the given object type is supported by this reader.- Specified by:
- canReadin interface- HttpMessageReader<Part>
- Parameters:
- elementType- the type of object to check
- mediaType- the media type for the read (possibly- null)
- Returns:
- trueif readable,- falseotherwise
 
- 
readMonopublic reactor.core.publisher.Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageReaderRead from the input message and decode to a single object.- Specified by:
- readMonoin interface- HttpMessageReader<Part>
- Parameters:
- elementType- the type of objects in the stream which must have been previously checked via- HttpMessageReader.canRead(ResolvableType, MediaType)
- message- the message to read from
- hints- additional information about how to read and decode the input
- Returns:
- the decoded object
 
- 
readpublic reactor.core.publisher.Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageReaderRead from the input message and decode to a stream of objects.- Specified by:
- readin interface- HttpMessageReader<Part>
- Parameters:
- elementType- the type of objects in the stream which must have been previously checked via- HttpMessageReader.canRead(ResolvableType, MediaType)
- message- the message to read from
- hints- additional information about how to read and decode the input
- Returns:
- the decoded stream of elements
 
 
- 
PartEventandPartEventHttpMessageReader