File download at the client tier can be performed via the ExportDisplay
interface obtained by calling the AppConfig.createExportDisplay()
static method or via injection in the controller class. For example:
AppConfig.createExportDisplay(this).show(fileDescriptor);
The show()
method accepts an optional ExportFormat
type parameter, which defines the type of the content and the file extension. If the format has not been provided, the extension
is retrieved from the FileDescriptor
, and the content type is set to application/octet-stream
.
When the user is working through the web interface, the file extension defines whether the file is downloaded via the browser’s
standard open/save dialog (Content-Disposition = attachment
), or if the browser will attempt to show the file in the browser window (Content-Disposition = inline
). The list of extensions for files that should be shown in the browser window is defined by the cuba.web.viewFileExtensions application property.