Class DefaultPartHttpMessageReader

java.lang.Object
org.springframework.http.codec.LoggingCodecsupport
org.springframework.http.codec.multipart.DefaultPartHttpMessageReader
All Implemented Interfaces:
HttpMessageReader<Part>

public class DefaultPartHttpMessageReader extends LoggingCodecsupport implements HttpMessageReader<Part>
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.

since:
5.3
Author:
Arjen Poutsma
  • Constructor Details

    • DefaultPartHttpMessageReader

      public&nbsp;DefaultPartHttpMessageReader()
  • Method Details

    • setMaxHeaderssize

      public&nbsp;void&nbsp;setMaxHeaderssize(int&nbsp;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
    • getMaxInMemorysize

      public&nbsp;int&nbsp;getMaxInMemorysize()
      Get the configured maximum in-memory size.
    • setMaxInMemorysize

      public&nbsp;void&nbsp;setMaxInMemorysize(int&nbsp;maxInMemorysize)
      Configure the maximum amount of memory allowed per part. When the limit is exceeded:

      By default this is set to 256K.

      Parameters:
      maxInMemorysize - the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory
    • setMaxDiskUsagePerPart

      public&nbsp;void&nbsp;setMaxDiskUsagePerPart(long&nbsp;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.

    • setMaxParts

      public&nbsp;void&nbsp;setMaxParts(int&nbsp;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.

    • setFilestorageDirectory

      public&nbsp;void&nbsp;setFilestorageDirectory(Path&nbsp;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.

      Throws:
      IOException - if an I/O error occurs, or the parent directory does not exist
    • setBlockingOperationscheduler

      public&nbsp;void&nbsp;setBlockingOperationscheduler(reactor.core.scheduler.scheduler&nbsp;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()
    • setHeadersCharset

      public&nbsp;void&nbsp;setHeadersCharset(Charset&nbsp;headersCharset)
      set 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:
    • getReadableMediaTypes

      public&nbsp;List<MediaType>&nbsp;getReadableMediaTypes()
      Description copied from interface:&nbsp;HttpMessageReader
      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 HttpMessageReader.getReadableMediaTypes(ResolvableType) for a more precise list.
      specified by:
      getReadableMediaTypes&nbsp;in interface&nbsp;HttpMessageReader<Part>
      Returns:
      the general list of supported media types
    • canRead

      public&nbsp;boolean&nbsp;canRead(ResolvableType&nbsp;elementType, @Nullable MediaType&nbsp;mediaType)
      Description copied from interface:&nbsp;HttpMessageReader
      Whether the given object type is supported by this reader.
      specified by:
      canRead&nbsp;in interface&nbsp;HttpMessageReader<Part>
      Parameters:
      elementType - the type of object to check
      mediaType - the media type for the read (possibly null)
      Returns:
      true if readable, false otherwise
    • readMono

      public&nbsp;reactor.core.publisher.Mono<Part>&nbsp;readMono(ResolvableType&nbsp;elementType, ReactiveHttpInputMessage&nbsp;message, Map<string,Object>&nbsp;hints)
      Description copied from interface:&nbsp;HttpMessageReader
      Read from the input message and decode to a single object.
      specified by:
      readMono&nbsp;in interface&nbsp;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
    • read

      public&nbsp;reactor.core.publisher.Flux<Part>&nbsp;read(ResolvableType&nbsp;elementType, ReactiveHttpInputMessage&nbsp;message, Map<string,Object>&nbsp;hints)
      Description copied from interface:&nbsp;HttpMessageReader
      Read from the input message and decode to a stream of objects.
      specified by:
      read&nbsp;in interface&nbsp;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