var blobToBase64 = function(blob, cb) { var reader = new FileReader(); reader.Onload= function() { var dataUrl = reader.result; var base64 = dataUrl.split(',')[1]; cb(base64); }; reader.readAsDataURL(blob); }; var base64ToBlob = function(base64, cb) { var binary = atob(base64); var len = binary.length; var buffer = new ArrayBuffer(len); var view = new Uint8Array(buffer); for (var i = 0; i view[i] = binary.charCodeAt(i); } cb(new Blob([view])); }; var base64ToBlobSync = function(base64) { var binary = atob(base64); var len = binary.length; var buffer = new ArrayBuffer(len); var view = new Uint8Array(buffer); for (var i = 0; i view[i] = binary.charCodeAt(i); } var blob = new Blob([view]); return blob; }; var blobToBase64_2 = function(blob, cb) { var reader = new FileReader(); reader.Onload= function() { var buffer = reader.result; var view = new Uint8Array(buffer); var binary = String.fromCharCode.apply(window, view); var base64 = btoa(binary); cb(base64); }; reader.readAsArrayBuffer(blob); };