Blob Examples

Contents Hide

  

The blob object is provided to assist the handling of binary data, as JavaScript only natively supports text strings. Data may be passed from the client side as a Blob which is an array of binary data.

Example 1. Create a blob object.

blob = new Blob(record.get(6));

 

var date = Calendar.getInstance().getTime();

var blob2 = new Blob(date.toString().getBytes());

 

var base64string = "<BASE64STRING>"

var base64bytes = Util.decodeBase64(varValue);

var blob3 = new Blob(base64bytes);

Note:

Example 2. Using the Byte Data

Passing blobs may be passed to BrightServer within record sets, but to use Blob data alone, you must convert the blob to a byte string. This may be achieved by the following code.

convertByteArrayToIntArray(blob.getBytes()));

Note:

Example 3. Compressed Records and Blobs

Blob data may be mapped to incorporate compression specified by a BrightXpress project. As such, in order to access these values to conventional BrightXpress project types, decompression must take place. Based on the table below,

The following data should be used to retrieve the correct decompressed byte data.

blob = new Blob(record.get(6));

blob.decompress();

Note:

Example 4. Writing Blobs from Files

fileName = "c:\\temp\\writefile.jpg";

blob.writeToFile(fileName);

Note:

Example 5. Reading Blobs from Files

fileName = "c:\\temp\\readfile.jpg";

blob.readFromFile(fileName);

Note: