Use Binary Data

Use Binary Data
lac31
You can store images, icons, pictures, documents, voice, video, and other binary data in 
Layer7 Live API Creator
 using various SQL database data types (for example, Binary Large OBjects (BLOBs) and Character Large OBjects (CLOBs)).
For more information about BLOBs and CLOBs, see BLOB, CLOB, Large Strings, Large Binary.
In this article:
 
 
Choose How API Creator Emits Binary Data
The JSON response format can return binary data as either Base64 or Hex. You can choose the encoding scheme for your API. API Creator attempts to return binary data inline if the size is less than the inline limit (the default value for the 
inlinelimit
 query parameter) and if you have chosen not to force binary data as an object. Base64 string format returns values beginning with 'b64' and Hex values return values beginning with '0x'.
For more information about how to choose the encoding scheme for your API, how to define the default values for the 
inlinelimit
 query parameter, and about how to force binary data as an object, see API Properties.
Retrieve Data
The following is an example of retrieving data using the Demo API sample application. The REST response shows the 
icon
 attribute emitted as an object of 
type
 Base64. The 
picture
 attribute returns a URL instead of a value. When the object length is greater than the default inline limit (the default value for the 
inlinelimit
 query parameter), then you can retrieve the 
/data/
 portion of that field using the URL.
For more information:
  • About the Demo API sample application, see Demo.
  • About how to define the default values for the 
    inlinelimit
     query parameter, see API Properties.
URI
 
In the REST Lab, select 
employee_picture
 and issue a GET:
https://localhost:8080/APIServer/
rest
/el-dev/demo/v1/demo%3Aemployee_picture
Response
 
The following response is expected:
employee_id": 1,
"icon": {
"type": "base64",
"length": 1185,
"value": "iVBORw0KGgoAAAANSUhEUgAAA... (truncated)"
},
"picture": {
"type": "base64",
"length": 138795,
"url": "https://server.acme.com/data/el-dev/demo/v1/demo:employee_picture/1/picture"
},
voice": {
"type": "base64",
"length": 127187,
"url": "https://server.acme.com/data/el-dev/demo/v1/demo:employee_picture/1/voice"
}
When you use a 
/data/
 link instead of a 
/rest/
 link, JSON returns a Base64-encoded 
icon
 string or a link to the picture or voice image.
URI
 
Use the following URL:
https://demodev.espressologic.com/
data
/el-dev/demo/v1/demo:employee_picture/1/picture
Response
 
The following response is expected:
{
"0": "�",
"1": "P",
"2": "N",
"3": "G",
"4": "
",
"5": "
",
"6": ".",
"7": "
",
"8": "",
"9": "", truncated ...