You use the Download OCL operator in a ViewModel to send binary file content to the client with a name that the downloaded file will use.
What Download does
Download triggers a client download from binary data that is already available in the ViewModel context. Supply:
- a file name, including its extension; and
- the file content as a
Bloborbyte[].
For example, a file name of meeting-notes.odt gives the downloaded file the .odt extension. A file name of report.pdf gives it the .pdf extension.
Availability
Use this operator in the context of a ViewModel. It is intended for a client-side download initiated from a ViewModel expression.
Arguments
| Argument | Type | Required value | Example |
|---|---|---|---|
| File name | String
|
The name assigned to the downloaded file, including its extension. | meeting-notes.odt
|
| File data | Blob or byte[]
|
The binary content to download. | A Blob containing the content of the ODT document. |
File-name requirement
Include the extension in the file name. The operator does not have a separately documented file-type argument. If you download an OpenDocument text file, use a name such as meeting-notes.odt, not meeting-notes.
Return value
The operator returns a Blob.
Example
Assume your ViewModel has access to a Blob containing an OpenDocument text document. Configure the download action to use:
- File name:
meeting-notes.odt - File data: the Blob that contains the document bytes
When the action runs, the client receives the binary content as a download named meeting-notes.odt.
Downloading data from a REST endpoint
Use Download when the binary data is available to the ViewModel as a Blob or byte array. If the file must instead be retrieved through a REST URL, use RestDownload. RestDownload performs a GET request to the specified endpoint and returns the response as a Blob.
