Class StreamingFileUpload

java.lang.Object
io.micronaut.http.multipart.StreamingFileUpload
All Implemented Interfaces:
Closeable, AutoCloseable

public final class StreamingFileUpload extends Object implements Closeable
A form file upload that is being streamed to the server. Unlike CompletedFileUpload, this class is never backed by a file. It exerts backpressure on the HTTP connection: If you read slowly or not at all, the upload will slow down on the client.

This object is closed when the request terminates. If you wish to use the data for longer, you need to call one of the consumption methods before that happens.

Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

  • Method Details

    • metadata

      public FormFieldMetadata metadata()
      Get the user-supplied metadata for this form field.
      Returns:
      The metadata
    • streamingBody

      public CloseableByteBody streamingBody()
      Stream the data as a CloseableByteBody as it comes in. This method may only be called once. The returned body must be closed by the caller.
      Returns:
      The streaming data
    • getDefinedSize

      public OptionalLong getDefinedSize()
      Get the final size of the upload, if given by the user.
      Returns:
      The final upload size
    • getName

      public String getName()
      Get the name of the form field.
      Returns:
      The form field name
      See Also:
    • getFilename

      public String getFilename()
      Get the user-specified file name of the uploaded file.
      Returns:
      The file name
      See Also:
    • close

      public void close()
      Close this form field, deleting any associated resources and files. If you called streamingBody() before, the returned object will still function.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • transferTo

      public Publisher<?> transferTo(File destination)
      A convenience method to write this uploaded item to disk.
      Parameters:
      destination - the destination of the file to which the stream will be written.
      Returns:
      A Publisher that outputs whether the transfer was successful
    • transferTo

      public Publisher<?> transferTo(Path destination)
      A convenience method to write this uploaded item to disk.
      Parameters:
      destination - the destination of the file to which the stream will be written.
      Returns:
      A Publisher that outputs whether the transfer was successful
    • transferTo

      public Publisher<?> transferTo(OutputStream outputStream)

      A convenience method to write this uploaded item the provided output stream.

      Parameters:
      outputStream - the destination to which the stream will be written.
      Returns:
      A Publisher that completes when the transfer is done
      Since:
      3.1.0
    • asInputStream

      public InputStream asInputStream()
      Create an InputStream that reads this file. The returned stream must be closed after use. The stream may block when data isn't yet available.
      Returns:
      An InputStream that reads this file's contents
      Since:
      4.2.0