Class CompletedFileUpload
java.lang.Object
io.micronaut.http.multipart.CompletedPart
io.micronaut.http.multipart.CompletedFileUpload
- All Implemented Interfaces:
Closeable, AutoCloseable
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 Summary
Modifier and TypeMethodDescriptionGet the content type of the file, if specified.final StringGet the file name provided by the user.abstract CompletedFileUploadThe completed part objects passed to a controller are closed when the associated request ends.static CompletedFileUploadofFile(FormFieldMetadata metadata, TemporaryFileResource path, long size) Create a new file-backed file upload.static CompletedFileUploadofMemory(FormFieldMetadata metadata, ReadBuffer memory) Create a new memory-backed file upload.abstract voidtransferTo(Path destination) Transfer this upload to the given file.Methods inherited from class CompletedPart
closeAsync, getBytes, getInputStream, getMetadata, getName, getSize, isInMemory, toReadBuffer
-
Method Details
-
moveResource
Description copied from class:CompletedPartThe 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 newCompletedPartwith the same data. You are responsible for closing the new part.- Specified by:
moveResourcein classCompletedPart- Returns:
- A new completed part
-
ofMemory
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 metadatamemory- 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 metadatapath- The backing filesize- The size of the backing file- Returns:
- The file upload structure
-
getContentType
-
getFilename
Get the file name provided by the user.- Returns:
- The file name
- See Also:
-
transferTo
Transfer this upload to the given file. This operation closes thisCompletedFileUpload. No further operations may be performed.- Parameters:
destination- The target file- Throws:
IOException
-