In this post (Creating a Blob from a base64 string in JavaScript) they take base64 and convert to a byte array. I haven't been able to figure out how to convert byte array back in to base64 code.
I tried using fromCharCode()
and btoa()
but had no luck.
Any tips on how to do this?
EDIT: Here is my code:
function decode_byteArray(result){
var binary = '';
var bytes = new Uint8Array(result);
var len = bytes.byteLength;
for (var i =0; i < len; i++){
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
This returns nothing when I try to print it out. The responseText from the XMLHTTPRequest does print out the byte array however.