Top Description Fields Constructors Methods
org.springframework.http.codec.multipart

public Class DefaultPartHttpMessageReader

extends LoggingCodecSupport
implements HttpMessageReader<Part>
Class Inheritance
All Implemented Interfaces
org.springframework.http.codec.HttpMessageReader
Imports
java.io.IOException, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Path, java.util.Collections, .List, .Map, java.util.concurrent.atomic.AtomicInteger, reactor.core.publisher.Flux, .Mono, reactor.core.scheduler.Scheduler, .Schedulers, org.springframework.core.ResolvableType, org.springframework.core.codec.DecodingException, org.springframework.core.io.buffer.DataBufferLimitException, org.springframework.http.MediaType, .ReactiveHttpInputMessage, org.springframework.http.codec.HttpMessageReader, .LoggingCodecSupport, org.springframework.lang.Nullable, org.springframework.util.Assert

Default 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.

Author
Arjen Poutsma
Since
5.3

Field Summary

Modifier and TypeField and Description
private Scheduler
private FileStorage
private Charset
private long
private int
private int
private int
Inherited from org.springframework.http.codec.LoggingCodecSupport:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the read (possibly null)
mediaType
)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.
private Scheduler
public int
getMaxInMemorySize()

Get the configured maximum in-memory size.

public List<MediaType>
getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader.
public Flux<Part>
read(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.
public Mono<Part>
readMono(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.
public void
setBlockingOperationScheduler(Scheduler blockingOperationScheduler)

Set the Reactor Scheduler to be used for creating files and directories, and writing to files.

public void
setFileStorageDirectory(Path fileStorageDirectory)

Set the directory used to store parts larger than maxInMemorySize.

public void
setHeadersCharset(Charset
the charset to use for decoding headers
headersCharset
)

Set the character set used to decode headers.

public void
setMaxDiskUsagePerPart(long maxDiskUsagePerPart)

Configure the maximum amount of disk space allowed for file parts.

public void
setMaxHeadersSize(int
the maximum amount of memory for headers
byteCount
)

Configure the maximum amount of memory that is allowed per headers section of each part.

public void
setMaxInMemorySize(int
the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory
maxInMemorySize
)

Configure the maximum amount of memory allowed per part.

public void
setMaxParts(int maxParts)

Specify the maximum number of parts allowed in a given multipart request.

private boolean
Inherited from org.springframework.http.codec.LoggingCodecSupport:
isEnableLoggingRequestDetailssetEnableLoggingRequestDetails

Field Detail

blockingOperationSchedulerback to summary
private Scheduler blockingOperationScheduler
fileStorageback to summary
private FileStorage fileStorage
headersCharsetback to summary
private Charset headersCharset
maxDiskUsagePerPartback to summary
private long maxDiskUsagePerPart
maxHeadersSizeback to summary
private int maxHeadersSize
maxInMemorySizeback to summary
private int maxInMemorySize
maxPartsback to summary
private int maxParts

Constructor Detail

DefaultPartHttpMessageReaderback to summary
public DefaultPartHttpMessageReader()

Method Detail

canReadback to summary
public boolean canRead(ResolvableType elementType, MediaType mediaType)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Doc from org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.

Parameters
elementType:ResolvableType

the type of object to check

mediaType:MediaType

the media type for the read (possibly null)

Returns:boolean

true if readable, false otherwise

Annotations
@Override
getBlockingOperationSchedulerback to summary
private Scheduler getBlockingOperationScheduler()
getMaxInMemorySizeback to summary
public int getMaxInMemorySize()

Get the configured maximum in-memory size.

getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Doc from org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return 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 via canWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, use getReadableMediaTypes(ResolvableType) for a more precise list.

Returns:List<MediaType>

the general list of supported media types

Annotations
@Override
readback to summary
public Flux<Part> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.read.

Doc from org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Flux<Part>

the decoded stream of elements

Annotations
@Override
readMonoback to summary
public Mono<Part> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Doc from org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Mono<Part>

the decoded object

Annotations
@Override
setBlockingOperationSchedulerback to summary
public void setBlockingOperationScheduler(Scheduler blockingOperationScheduler)

Set the Reactor Scheduler to 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 maxInMemorySize is set to -1.

See Also
Schedulers#boundedElastic
setFileStorageDirectoryback to summary
public void setFileStorageDirectory(Path fileStorageDirectory) throws IOException

Set the directory used to store parts larger than maxInMemorySize. By default, a directory named spring-webflux-multipart is created under the system temporary directory.

Note that this property is ignored when maxInMemorySize is set to -1.

Exceptions
IOException:
if an I/O error occurs, or the parent directory does not exist
setHeadersCharsetback to summary
public void setHeadersCharset(Charset headersCharset)

Set the character set used to decode headers. Defaults to UTF-8 as per RFC 7578.

Parameters
headersCharset:Charset

the charset to use for decoding headers

Since
5.3.6
See Also
RFC-7578 Section 5.1
setMaxDiskUsagePerPartback to summary
public 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 maxInMemorySize is set to -1.

setMaxHeadersSizeback to summary
public void setMaxHeadersSize(int byteCount)

Configure the maximum amount of memory that is allowed per headers section of each part. When the limit

Parameters
byteCount:int

the maximum amount of memory for headers

setMaxInMemorySizeback to summary
public void setMaxInMemorySize(int maxInMemorySize)

Configure the maximum amount of memory allowed per part. When the limit is exceeded:

By default this is set to 256K.

Parameters
maxInMemorySize:int

the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory

setMaxPartsback to summary
public 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.

tooManyPartsback to summary
private boolean tooManyParts(AtomicInteger partCount)