Page 1 of 1

Retrieving photo base 64 string from an image component

Posted: Fri Jun 05, 2015 1:54 pm
by Leonardo Valentin Zeferino

Hi!

I'm trying to get a base64 of an image and use in uploadBinaryHelper with the code bellow.

code//Get img component. You should replace "mobileimage_1" with your img component name.
var img = Apperyio('item_img_61');
img.attr('crossOrigin', 'anonymous');
var width = img.width();
var height = img.height();
var canvas = jQuery('<canvas width="' + width + '" height="' + height + '"></canvas>');
var c = canvas[0];
var ctx = c&#46;getContext("2d");
ctx&#46;drawImage(img[0], 0, 0, width, height);
&#47;&#47;Get base64String&#46;
var base64String = c&#46;toDataURL();
&#47;&#47;var base64String = "data:image/png;base64," + c&#46;toDataURL();
&#47;&#47;Using base64String&#46;
console&#46;log(base64String);
alert(base64String);

uploadBinaryHelper(webUploadCheckin, base64String);
/code

But occoured the follow error:

codeUncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported&#46;/code

Could you help me?


Retrieving photo base 64 string from an image component

Posted: Fri Jun 05, 2015 3:07 pm
by Serhii Kulibaba

Retrieving photo base 64 string from an image component

Posted: Fri Jun 05, 2015 3:27 pm
by Leonardo Valentin Zeferino

Thanks, Sergiy!

I had forgotten the crossorigin property in image tag.

code<img id="xxx" crossorigin="anonymous" src="xx">/code

Thanks!


Retrieving photo base 64 string from an image component

Posted: Tue Jun 30, 2015 9:08 pm
by Joe7349603

Leonardo,

I have similar issue, if you don't mind sharing, where did you stick the line above, how did you final solution end up looking like?


Retrieving photo base 64 string from an image component

Posted: Wed Sep 09, 2015 3:36 pm
by Joe Sharples

Hi,
did you find a final solution for this?