The value of defined binary
logic object or
dictionary item data is represented as a
JSON object with
"metadata" and
"content" properties. If the object does not contain any data, its value is represented as
null.
Localhost URL: The binary data is serialized as a
localhost URL. Localhost URLs are only valid while the CSPro application is running. This is the default option, as it is an efficient way to write the data for use in
web views. This value, serialized in the object
"content" with the property
"url", may look like:
{
"metadata": {
"path": "C:/texts/pangram.txt",
"filename": "pangram.txt",
"mime": "text/plain"
},
"content": {
"url": "http://localhost:59421/vf/4/pangram.txt"
}
}
Data URL: The binary data is serialized as a
data URL encoded in
Base64. Unlike a localhost URL, a data URL is not temporary so it is a good choice if you need a URL that can permanently refer to the data. Data URLs are approximately 33% larger than the content itself, so using data URLs for large files is not advised. This value, serialized in the object
"content" with the property
"url", may look like:
{
"metadata": {
"path": "C:/texts/pangram.txt",
"filename": "pangram.txt",
"mime": "text/plain"
},
"content": {
"url": "data:text/plain;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyAxMjM0NTY3ODkw"
}
}
Copying and pasting that URL into a web browser's address bar will show the English pangram: "The quick brown fox jumps over the lazy dog 1234567890".
There are several ways to set binary data using JSON. If you want to clear a value, specifying the value as null will reset binary data to its default state. To set binary data to a specific value, you must supply an object with a "content" property and, optionally, a "metadata" property. Metadata is specified as an object with key/value pairs. The content itself can be specified in a couple ways:
Data URL: The binary data can be specified as a
data URL using the
"url" property. CSPro can parse data URLs encoded using
Base64 or
percent-encoding. For example:
string data_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAIAAAAW4yFwAAAAEElEQVR4nGP4z/CfgSH+BAANggMmwP+nGgAAAABJRU5ErkJggg==";
Image tiny_image;
tiny_image.setValueFromJson(maketext("{ \"content\": { \"url\": \"%s\" } }", data_url));
// width = 1, height = 2
errmsg("width = %d, height = %d", tiny_image.width(), tiny_image.height());
File on Disk: The binary data can be specified as a file using the "path" property. The path is evaluated relative to the location of the application. For example:
Some binary objects have additional ways that data can be supplied for deserialization. For more information about the serialization of binary data, see the documentation for each object: