🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Upload and Download Files and Images in MDriven Turnkey
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

You can let users upload, display, and download files or images in a MDriven Turnkey application by exposing Blob attributes through a ViewModel; this guide is for MDriven Designer users who model those attributes and views.

Overview

A Blob is an attribute that stores file or image bytes. In Turnkey, how a Blob is rendered depends on the Blob type and the ViewModel column settings:

Goal Model and ViewModel setup Result in Turnkey
Upload a file Add a writable Blob attribute to a class and expose it in a ViewModel as a non-read-only column. An upload button. Its text comes from the ViewModel column name.
Download a file Expose the Blob in a ViewModel and set the Blob ViewModel column to isStatic. Add the BlobDownloadLink tagged value when you want a download link. Store matching filename and content-type attributes. A downloadable Blob with the correct file name and content type.
Upload an image Add a Blob attribute and set its BlobType property to Image. Expose it as a writable ViewModel column. An image upload control.
Show an existing image Expose the image Blob as a read-only expression column, or set its ViewModel column to isStatic. The image is presented without an upload control.

Upload a file

Model the file attributes

  1. In MDriven Designer, add a Blob attribute to the class that owns the file. For example, add Attachment to a Document class.
  2. Add a String attribute named Attachment_FileName to the same class. Turnkey sets this attribute to the uploaded file name.
  3. If you will provide a download link, add a String attribute named Attachment_ContentType as well. Store the uploaded file's content type in this attribute so Turnkey can create the download link correctly.

The filename and content-type attribute names are based on the Blob attribute name. For a Blob named Attachment, use Attachment_FileName and Attachment_ContentType.

Example class attribute Type Purpose
Attachment Blob The uploaded file bytes.
Attachment_FileName String The uploaded file name, such as proposal.pdf.
Attachment_ContentType String The file content type used for a correct download link.

A Blob backing attribute can also be a derived settable attribute. Use this when assigning the uploaded bytes must run model logic, such as processing the incoming file before it is retained.

Expose the Blob for upload

  1. Create or open the ViewModel that edits the object, for example a Document edit ViewModel.
  2. Add a ViewModel column for the Blob attribute, for example Attachment.
  3. Ensure that the column is not read-only.
  4. Publish or run the Turnkey application and open the view.

Turnkey renders the writable Blob column as an upload button. The button text is based on the ViewModel column name. For example, a column named Attachment produces an upload control identified by that column name.

Download a file

To present a Blob as a file download, configure the Blob column as a static value in the ViewModel and provide the file metadata attributes described above.

  1. Add the Blob attribute to the ViewModel.
  2. Select the ViewModel column containing the Blob and set isStatic.
  3. Add the BlobDownloadLink tagged value to create a download link for that Blob.
  4. Include and populate the matching <BlobName>_FileName and <BlobName>_ContentType String attributes.

For example, when Document.Attachment contains the bytes for a PDF, Attachment_FileName can contain proposal.pdf and Attachment_ContentType stores its content type. Turnkey uses this metadata when it creates the download link.

Upload and display images

Mark the Blob as an image

  1. Add a Blob attribute to the class, for example EmployeePhoto on an Employee class.
  2. In the attribute properties area in MDriven Designer, set BlobType to Image.
  3. Add the attribute to a ViewModel as a writable column to allow image upload.

The BlobType setting tells Turnkey that the Blob is an image rather than a general file.

Display an image without allowing upload

Use either of these ViewModel approaches when users must see an image but must not replace it:

  • Make the image column a read-only expression.
  • Set isStatic for the image ViewModel column.

For example, an employee-details ViewModel can show EmployeePhoto as a static column while a separate employee-edit ViewModel exposes it as writable.

Image data reached through an expression

When a ViewModel column uses an expression to reach the byte array, Turnkey cannot infer whether the value is an image or a general file. Add this tagged value to the ViewModel column:

Eco.BlobType=Image

This tagged value applies to the ViewModel column, not to the underlying class attribute. Use it, for example, when an expression resolves an employee photo through a related object instead of directly exposing the image Blob attribute.

Store blobs outside the database

You can use BlobStorage when you do not want files and images stored in the database. This is an alternative storage choice; the Blob attributes and ViewModel presentation described on this page still define how users work with the file or image in Turnkey.

Upload multiple files

A normal writable Blob column uploads one file to its target Blob. If a user must select and upload several files in one operation, use the dedicated multiple file upload component. That component creates a target object for each file and uploads the files in sequence.

Implementation note for custom clients

Turnkey's browser client uses JavaScript generated from TypeScript to upload files. The Turnkey server endpoint used for multipart upload is named UploadFileMultiPartController. If you build a custom client, inspect the Turnkey JavaScript or TypeScript implementation and reproduce the required upload behavior there.

Checklist

Before testing, confirm the following:

  • The data-owning class has a Blob attribute.
  • The upload ViewModel exposes that Blob in a column that is not read-only.
  • A file Blob has a matching <BlobName>_FileName String attribute.
  • A downloadable Blob also has a matching <BlobName>_ContentType String attribute, its ViewModel column has isStatic, and the column has the BlobDownloadLink tagged value.
  • An image Blob has BlobType set to Image, or an expression-based image column has Eco.BlobType=Image.
  • Multi-file requirements use the multiple file upload component rather than one standard Blob upload column.

See also