You can use Column.BlobDownloadLink on a ViewModel column to let users download Blob data, such as a PDF, instead of trying to display it as an image.
Use BlobDownloadLink
Set BlobDownloadLink=true on the ViewModelColumn that contains the file data. The UI renders that column as a download link.
Use this for Blob content that should be downloaded, for example a PDF stored in a Blob attribute. For Blob attribute types, see Documentation:Attribute.Eco.BlobType.
Example
A ViewModel has a Blob column named InvoicePdf. Tag InvoicePdf with BlobDownloadLink=true. When the ViewModel is shown, the user can select the rendered link to download the PDF.
What happens when a user downloads
The UI requests the file through GetVMFile on the Turnkey server. Unless you provide a content-type companion column, the downloaded response uses:
application/octet-stream
If the request includes accept-encoding: gzip, the server gzips the file before sending it. In that case, the response includes a content-encoding: gzip header and content-length is the compressed length.
Set the content type
Add an optional string ViewModelColumn named <BlobColumn>_ContentType at the same ViewModel nesting as the Blob download column. The column does not need to be visible, but it must exist in the ViewModel.
For the InvoicePdf example, add:
| ViewModelColumn | Type | Example value | Result |
|---|---|---|---|
InvoicePdf
|
Blob | PDF file data | The file to download. |
InvoicePdf_ContentType
|
String | application/pdf
|
The download response uses this content type. |
Use a web-standard MIME type for the value. If this companion column is absent, the response content type remains application/octet-stream.
Set the download filename
Add an optional string ViewModelColumn named <BlobColumn>_FileName at the same ViewModel nesting as the Blob download column. The name is case-sensitive. This column can be hidden, but it must exist in the ViewModel.
For the same example, add InvoicePdf_FileName with a value such as invoice-1042.pdf. GetVMFile then marks the response as an attachment and supplies that filename to the browser.
The filename is set during upload. Therefore, include the _FileName column in the ViewModel used to upload the Blob if you want the downloaded file to retain its name.
Checklist
- Store the document in a Blob column.
- Set
BlobDownloadLink=trueon that ViewModelColumn. - Add
<BlobColumn>_ContentTypeas a string column when the downloaded MIME type must be specified. - Add
<BlobColumn>_FileNameas a string column when the browser should receive a specific attachment filename. - Keep both optional companion columns at the same ViewModel nesting as the Blob column. Their names must match the Blob column name exactly;
_FileNameis case-sensitive.
See also
[[Category:Attributes and data types [Beginner]]]
