leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How do I get the content of an image in the media manager using its filename

Hi
I need to get the base64 string of an image uploaded to the media manager. (eg a logo)
I tried using $scope.imgsrc=Apperyio.getImagePath('rtlogonew.png'); but getImagePath "is not a function" error is returned in the console. I cannot see another example in the documentation or the forum.

My app is Angular, not Ionic.

How do I get the image content, ideally in base64 format?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How do I get the content of an image in the media manager using its filename

Hello Steve,

1) Apperyio.getImagePath works only in JQM apps

2) Ionic app is based on AngularJS

3) You can read it's base64 content by it's full path:

http://stackoverflow.com/questions/22...

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How do I get the content of an image in the media manager using its filename

Thanks. I tried using a full path based on another forum post but it returned an error.
If my image is uploaded to the media manager as "sergiy.png" how would I reference that as a full path please ?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How do I get the content of an image in the media manager using its filename

The path will be "files/images/sergiy.png".

prevar oReq = new XMLHttpRequest();
oReq.open("GET", "files/images/sergiy.png", true);
oReq.responseType = "arraybuffer";

oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response; // Note: not oReq.responseText
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
for (var i = 0; i < byteArray&#46;byteLength; i++) {
&#47;&#47; do something with each byte in the array
}
}
};

oReq&#46;send(null);/pre
More information here: https://developer.mozilla.org/en-US/d...

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How do I get the content of an image in the media manager using its filename

Thanks Sergiy. If I was to set the responseType to "blob" instead does that give me the image buyes that I can then assign to an image "src" attribute?
Or do I always need to convert whatever is returned to base64 first ?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How do I get the content of an image in the media manager using its filename

If you need to display that image in the src attribute - please set it's path to that attribute, e.g.:
presrc=files/images/sergiy&#46;png/pre

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

How do I get the content of an image in the media manager using its filename

Thanks Sergiy, That worked fine.

Can I just also point out that if you rename an image in the Media Manager, the original file still appears in the Source files list under WEB_RESOURCES/files/images. In my opinion you should remove the original file if you rename it because if you rename 50 files then your app will have 100 files and use up twice as much space for the images.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How do I get the content of an image in the media manager using its filename

Hi Steve - thank you for pointing this out, we have reported this to our development team.

Return to “Issues”