Class StreamingFileUpload
java.lang.Object
io.micronaut.http.multipart.StreamingFileUpload
- All Implemented Interfaces:
Closeable, AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate anInputStreamthat reads this file.voidclose()Close this form field, deleting any associated resources and files.Get the final size of the upload, if given by the user.Get the user-specified file name of the uploaded file.getName()Get the name of the form field.metadata()Get the user-supplied metadata for this form field.Stream the data as aCloseableByteBodyas it comes in.Publisher<?> transferTo(File destination) A convenience method to write this uploaded item to disk.Publisher<?> transferTo(OutputStream outputStream) A convenience method to write this uploaded item the provided output stream.Publisher<?> transferTo(Path destination) A convenience method to write this uploaded item to disk.
-
Constructor Details
-
StreamingFileUpload
-
-
Method Details
-
metadata
Get the user-supplied metadata for this form field.- Returns:
- The metadata
-
streamingBody
Stream the data as aCloseableByteBodyas it comes in. This method may only be called once. The returned body must be closed by the caller.- Returns:
- The streaming data
-
getDefinedSize
Get the final size of the upload, if given by the user.- Returns:
- The final upload size
-
getName
-
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 calledstreamingBody()before, the returned object will still function.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
transferTo
-
transferTo
-
transferTo
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
Publisherthat completes when the transfer is done - Since:
- 3.1.0
-
asInputStream
Create anInputStreamthat reads this file. The returned stream must be closed after use. The stream may block when data isn't yet available.- Returns:
- An
InputStreamthat reads this file's contents - Since:
- 4.2.0
-