So what I did up to now :
I have a file "http://www.example.com/picture.png"
And I read it into a variable
function aGET(uri, callback) {
let xhttp = new XMLHttpRequest();
xhttp.open("GET", uri );
xhttp.send();
xhttp.onreadystatechange = function() {
if ( this.readyState === 4 && callback ) {
callback(xhttp.responseText);
};
};
}
uurl = "http://www.example.com/picture.png";
aGET(uurl, function(logoImage) {
console.log("logoImage : "+logoImage);
});
At this moment logoImage looks like this, it is a binary format but does not appear to be a blob:
�PNG
� ��� IHDR�������v�������ܛ����zTXtRaw profile type exif��x��Yr#9�E��
because when I tried to transform it into a base64 with btoa
aGET(uurl, function(logoImage) {
var base64EncodedStr = "data:image/png;base64," + btoa(unescape(encodeURIComponent(logoImage)));
console.log("base64EncodedStr : "+base64EncodedStr );
});
I received some wired string that looks like a base64 but is none.
data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAA
So my Question is still open: How can I transform it into base64 to get something like this :