Page 1 of 1

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

Posted: Sun Nov 06, 2016 11:27 pm
by leven.steve

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?


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

Posted: Mon Nov 07, 2016 11:12 am
by Serhii Kulibaba

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...


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

Posted: Mon Nov 07, 2016 11:44 am
by leven.steve

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 ?


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

Posted: Tue Nov 08, 2016 10:55 am
by Serhii Kulibaba

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...


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

Posted: Tue Nov 08, 2016 1:25 pm
by leven.steve

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 ?


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

Posted: Wed Nov 09, 2016 7:28 am
by Serhii Kulibaba

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


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

Posted: Wed Nov 09, 2016 11:17 am
by leven.steve

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.


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

Posted: Wed Nov 09, 2016 2:27 pm
by Illya Stepanov

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