Is it possible to get a byte array of an image stored in Tridion using the Anguilla JavaScript API? I would like to display an image in a GUI extension popup window.
The easiest way I can think of is by simply loading the MMC using a URL like this:
http://<hostname>/WebUI/Editors/CME/icon.png?uri=tcm:2-1151
If you use that approach the actual loading of the bytes has nothing to do with Tridion anymore: you're just loading an image from a URL.
You'll probably want to construct the URL in JavaScript, so start with something like this (which I shamelessly copied from the source code):
p.multimediaUrl = $display.getMultimediaHandlerPath() + "?uri={0}";
As usual the Mozilla Developer Connection has a great example on loading binary data with XMLHttpRequest. Applied to this situation, I seem to get the data with this snippet:
var arraybuffer;
var xhr = new XMLHttpRequest();
xhr.open("GET", $display.getMultimediaHandlerPath() + '?uri==tcm%3A2-1151', true);
xhr.responseType = "arraybuffer";
xhr.onload = function(e) {
arraybuffer = xhr.response; // not responseText
}
xhr.send();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With