I've been trying to find a way to Base64 encode binary data with JavaScript for the past few hours and it turns out that btoa() only works with strings so I came up with the following code, where blob is the file I need to encode:
function base64Encode(blob) {
var reader = new FileReader();
reader.readAsDataURL(blob)
reader.onloadend = function() {
console.log(reader.result);
};
};
Problem is, base64Encode(blob) always returns undefined, does anybody know a fix?