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.
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:
record.get(6) is of type byte[] and is used to initialise 'blob' initially.
date is the current date now, which will be converted to string and then read as 'blob2'.
base64bytes is the converted value of base64string, using the Util.decodeBase64() method to retrieve an byte[] for 'blob3'.
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:
convertByteArrayToIntArray – a method that takes in raw binary data.
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:
record.get(6) corresponds to row number 6 in the table above.
Similarly, to store these values correctly, compression of blobs must be undertaken.
fileName = "c:\\temp\\writefile.jpg";
blob.writeToFile(fileName);
Note:
fileName - variable full path of the binary file to be written.
fileName = "c:\\temp\\readfile.jpg";
blob.readFromFile(fileName);
Note:
fileName - variable full path of the binary file to be written.