Work with the Temp Blob object

Completed

A binary large object (BLOB) is a complex data type. Variables of this data type differ from normal numeric and string variables in that BLOBs have a variable length. The maximum size of a BLOB object is 2 gigabytes. You can use BLOBs to store memos (text), pictures (bitmaps), or user-defined types.

You can read from and write to BLOBs by creating input and output streams, respectively. To do so, use the CreateInStream method (BLOB) and the CreateOutStream method (BLOB) to read and write to BLOBs.

To optimize performance, when you access a record that has a BLOB field, the data in the BLOB isn't always read into memory. You must call the CalcFields method (Record) to read the BLOB into memory and calculate it. Then, you can use the BLOB in AL code or display it in the application.

var

    CompanyInformation: Record \"Company Information\";

    InStr: InStream;

begin

    if(CompanyInformation.FindFirst()) then begin 

        CompanyInformation.CalcFields(CompanyInformation.Picture);

        CompanyInformation.Picture.CreateInStream(InStr);

    end;

end;

To help you as a developer, when you're writing code to manage the importing and exporting of files, you can use the Temp Blob codeunit (4100). This codeunit is part of the ALAppExtensions Repository.

The supported methods in the Temp Blob codeunit include:

  • CreateInStream - Creates an InStream object to read data from the BLOB. You can optionally provide an Encoding parameter to this function.

  • CreateOutStream - Creates an OutStream object to write data to the BLOB. You can optionally provide an Encoding parameter to this function.

  • Length - Returns the number of bytes in the BLOB.

  • HasValue - Determines whether the BLOB has a value.

You can use the Temp Blob codeunit to convert InStream objects from and to OutStream objects.