Package com.vaadin.flow.server.streams
Class FileDownloadHandler
java.lang.Object
com.vaadin.flow.server.streams.TransferProgressAwareHandler<DownloadEvent,R>
com.vaadin.flow.server.streams.AbstractDownloadHandler<FileDownloadHandler>
com.vaadin.flow.server.streams.FileDownloadHandler
- All Implemented Interfaces:
DownloadHandler
,ElementRequestHandler
,Serializable
Download handler for use with a given File that will be read and written as
binary data to the response.
- Since:
- 24.8
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionFileDownloadHandler
(File file) Create a download handler for given file.FileDownloadHandler
(File file, String fileNameOverride) Create a download handler for given file. -
Method Summary
Modifier and TypeMethodDescriptionprotected TransferContext
getTransferContext
(DownloadEvent transferEvent) This method is used to get the transfer context from the transfer events (e.g.Optional URL postfix allows appending an application-controlled string, e.g.void
handleDownloadRequest
(DownloadEvent downloadEvent) Method that is called when the client wants to download from the url stored for this specific handler registration.Methods inherited from class com.vaadin.flow.server.streams.AbstractDownloadHandler
getContentType, inline, isInline
Methods inherited from class com.vaadin.flow.server.streams.TransferProgressAwareHandler
addTransferProgressListener, getListeners, notifyError, onProgress, onProgress, onProgress, onProgress, whenComplete, whenComplete, whenStart, whenStart
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.server.streams.DownloadHandler
handleRequest
Methods inherited from interface com.vaadin.flow.server.streams.ElementRequestHandler
getDisabledUpdateMode, isAllowInert
-
Constructor Details
-
FileDownloadHandler
Create a download handler for given file. Url postfix will be used asfile.getName()
.The downloaded file name and download URL postfix will be set to
file.getName()
. If you want to use a different file name, useFileDownloadHandler(File, String)
instead.- Parameters:
file
- file to download
-
FileDownloadHandler
Create a download handler for given file.The downloaded file fileNameOverride and download URL postfix will be set to
fileNameOverride
.- Parameters:
file
- file to downloadfileNameOverride
- used as a downloaded file name (overridesfile.getName()
) and also as a download request URL postfix, e.g./VAADIN/dynamic/resource/0/5298ee8b-9686-4a5a-ae1d-b38c62767d6a/my-file.txt
-
-
Method Details
-
handleDownloadRequest
Description copied from interface:DownloadHandler
Method that is called when the client wants to download from the url stored for this specific handler registration.- Parameters:
downloadEvent
- download event containing the necessary data for writing the response- Throws:
IOException
- if an IO error occurred during download
-
getUrlPostfix
Description copied from interface:ElementRequestHandler
Optional URL postfix allows appending an application-controlled string, e.g. the logical name of the target file, to the end of the otherwise random-looking download URL. If defined, requests that would otherwise be routable are still rejected if the postfix is missing or invalid. Postfix changes the last segment in the resource url.- Returns:
- String optional URL postfix, or
null
for "".
-
getTransferContext
Description copied from class:TransferProgressAwareHandler
This method is used to get the transfer context from the transfer events (e.g.DownloadEvent
).- Overrides:
getTransferContext
in classAbstractDownloadHandler<FileDownloadHandler>
- Parameters:
transferEvent
- the transfer event- Returns:
- the transfer context
-