var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://static.reddit.com/reddit.com.header.png', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if (this.status == 200) {
var uInt8Array = new Uint8Array(this.response);
var byte3 = uInt8Array[4];
var bb = new WebKitBlobBuilder();
bb.append(xhr.response);
var blob = bb.getBlob('image/png');
var base64 = window.btoa(blob);
alert(base64);
}
};
xhr.send();
Basically, what I am trying to do here is retrieve an image, and convert it to base64.
From reading in the comments here, it states:
"Sure. After fetching a resource as an ArrayBuffer, create a blob from it. Once you have that, you could base64 encode the file/blob directly
window.btoa()
orFileReader.readAsDataURL()
."
However, blob
is just [object blob]
, while I need to get the binary from the image so I can convert it to base64 and display it in a img tag using data.
Anyone know how to achieve this?
Thank you in advance!