问题
I am using btoa and atob for Base64 but the atob method doesn't work on binary data! Just text. How can I solve this?
if(!!window.createBlobURL || !!window.createObjectURL) {
var bb = new BlobBuilder();
var reader = new FileReader();
var url_creator = window.createBlobURL || window.createObjectURL;
bb.append(atob(msg.bit.file.data));
reader.onloadend = function(e) {
bb = new BlobBuilder();
bb.append(e.target.result);
var url = url_creator(bb.getBlob(msg.bit.file.type));
window.open(url);
}
reader.readAsBinaryString(bb.getBlob(msg.bit.file.type));
}
Where msg.bit.file.data is the base64 encoded file.
回答1:
If your data is binary already (TypedArray) append on the BlobBuilder should just work.
If the data is returned from XMLHttpRequest in Chrome at least you have access to responseBlob property, which can be used directly in BlobBuilder.append()
来源:https://stackoverflow.com/questions/4351543/are-google-chrome-base64-methods-capable-of-handling-binary-data-from-the-file-a