Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get multimedia component byte array using Tridion Anguilla framework?

Tags:

tridion

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.

like image 562
robrtc Avatar asked Dec 02 '12 21:12

robrtc


1 Answers

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}";

Update

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();    
like image 74
Frank van Puffelen Avatar answered Oct 04 '22 18:10

Frank van Puffelen