Class CompletedFileUpload

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

public abstract sealed class CompletedFileUpload extends CompletedPart
Represents a completed part of a multipart request. May be backed by a file or memory depending on server configuration.

When used as an argument to an Controller instance method, the route is not executed until the part has been fully received. Provides access to metadata about the file as well as the contents.

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.0
Author:
Zachary Klein
  • Method Details

    • moveResource

      public abstract CompletedFileUpload moveResource()
      Description copied from class: CompletedPart
      The completed part objects passed to a controller are closed when the associated request ends. If you want to keep them around for longer, you can use this method to create a new CompletedPart with the same data. You are responsible for closing the new part.
      Specified by:
      moveResource in class CompletedPart
      Returns:
      A new completed part
    • ofMemory

      public static CompletedFileUpload ofMemory(FormFieldMetadata metadata, ReadBuffer memory)
      Create a new memory-backed file upload. Ownership of the data buffer transfers to the file upload object. Closing the file upload object will close the memory.
      Parameters:
      metadata - The field metadata
      memory - The field data
      Returns:
      The file upload structure
    • ofFile

      public static CompletedFileUpload ofFile(FormFieldMetadata metadata, TemporaryFileResource path, long size)
      Create a new file-backed file upload. Ownership of the file transfers to the file upload object. Closing the file upload object will delete the backing file.
      Parameters:
      metadata - The field metadata
      path - The backing file
      size - The size of the backing file
      Returns:
      The file upload structure
    • getContentType

      public final Optional<MediaType> getContentType()
      Get the content type of the file, if specified.
      Returns:
      The content type
      See Also:
    • getFilename

      public final String getFilename()
      Get the file name provided by the user.
      Returns:
      The file name
      See Also:
    • transferTo

      public abstract void transferTo(Path destination) throws IOException
      Transfer this upload to the given file. This operation closes this CompletedFileUpload. No further operations may be performed.
      Parameters:
      destination - The target file
      Throws:
      IOException