🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Blob
This page was created by Stephanie on 2024-05-15. Last edited by Wikiadmin on 2026-07-29.

You use a Blob attribute in MDriven Designer to store binary file content—such as a document or image—on a modeled object and present it in a ViewModel in MDriven Turnkey.

What a Blob is

BLOB means Binary Large Object. A Blob holds a sequence of bytes as one attribute value. The bytes can represent a PDF, an image, an audio file, a video file, or other file content. A Blob can also hold encoded text when an integration requires bytes rather than a String.

For example, a Document class can have a File Blob attribute. One Document instance then holds the complete content of one uploaded PDF in File.

A Blob stores the content; it does not by itself describe how a user interface should display or download that content. Model the file metadata and set the Blob type when required.

Model a file Blob

In MDriven Designer, add a Blob attribute to the class that owns the file.

  1. Select the class that should own the file. For example, select Document.
  2. Add an attribute, for example File.
  3. Set the attribute type to Blob.
  4. Add a String attribute named File_FileName to retain the uploaded file name.
  5. Add a String attribute named File_ContentType to retain the file content type.

The _FileName and _ContentType suffixes use the Blob attribute name as their prefix. For the File Blob, use File_FileName and File_ContentType.

Attribute Type Purpose
File Blob The binary content of the uploaded file.
File_FileName String The uploaded name, such as contract.pdf.
File_ContentType String The content type used when Turnkey creates a download link.

Model an image Blob

A Blob is not automatically an image. If the content is an image that you want the user interface to render as an image, set the Blob attribute's BlobType property to Image in MDriven Designer.

For example, add a ProfilePicture attribute of type Blob to Customer and set its BlobType to Image. A ViewModel that presents ProfilePicture can then display the stored content as an image.

If a ViewModel column uses an expression to reach the image bytes instead of directly using the image attribute, Turnkey cannot infer that the bytes are an image. Add the tagged value Eco.BlobType=Image to that ViewModel column.

Use a Blob in a Turnkey ViewModel

Add the Blob attribute to a ViewModel to let users work with the file in MDriven Turnkey.

  • A non-read-only Blob or image column renders as an upload control. The ViewColumn name supplies the text shown in that control.
  • Use a read-only expression or select isStatic on the ViewModel column when you want to present an image without allowing upload.
  • For a non-image Blob, configure downloading rather than expecting the browser to render the binary content as an image.

For the full upload and download procedure, including ViewModel configuration, see HowTos:Upload and Download Files and Images in MDriven Turnkey.

Download non-image files

A PDF, spreadsheet, or other non-image Blob needs download behavior. Add the Blob to the ViewModel and use the download-link configuration described in Documentation:Column.BlobDownloadLink. The corresponding _FileName and _ContentType attributes allow Turnkey to create a download link with the correct file name and content type.

For example, a Document.File Blob with Document.File_FileName set to contract.pdf is presented as a downloadable file rather than as an image.

When an OCL action needs to send generated bytes to the client, use Download. It accepts a file name and Blob (byte array) in a ViewModel context.

Convert and process Blob values

Blob values are byte arrays. Use the available OCL operations when an integration or calculation needs an encoded String or when it returns encoded data.

Need Use Example
Convert a Blob to a Base64 String BlobToBase64 Customer.allInstances()->first().ProfilePicture.BlobToBase64
Convert a Base64 String to a Blob Base64ToBlob 'My clear text string'.StringToBase64.Base64ToBlob
Compress or decompress Blob bytes SysSingleton.Deflate Pass the Blob and the appropriate inflate Boolean value.
Compute a SHA-256 or SHA-512 hash, or format bytes as a String SHA512ComputeHash, SHA256ComputeHash and BitConverterToString Pass the Blob to the relevant SysSingleton method.

Store large files outside the model database

For large files, you can keep Blob content outside the granular model database with Blob Storage. Add the tagged value ExternalBlobStorage = true to the Blob, Text, or Image attribute.

External Blob Storage is a Turnkey feature. With the out-of-the-box storage option, files are stored on disk under App_Data/BlobStorage and named Class.Attribute.Guid.blob. These stored files are not automatically cleaned, so plan how your application will manage files that are no longer needed.

See also

[[Category:Attributes and data types [Beginner]]