是谷歌浏览器的Base64方法能够从文件API处理二进制数据? [英] Are Google Chrome Base64 methods capable of handling binary data from the File API?
本文介绍了是谷歌浏览器的Base64方法能够从文件API处理二进制数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用BTOA和ATOB为Base64编码,但ATOB方法不能在二进制数据的工作!只是文本。我怎样才能解决这个问题?
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));
}
在哪里msg.bit.file.data是为Base64 EN codeD文件。
Where msg.bit.file.data is the base64 encoded file.
推荐答案
如果您的数据是二进制已经(TypedArray)追加对BlobBuilder应该只是工作。
If your data is binary already (TypedArray) append on the BlobBuilder should just work.
如果该数据是从XMLHtt prequest在Chrome回来,至少你有机会获得responseBlob属性,它可以直接在BlobBuilder.append使用()
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()
这篇关于是谷歌浏览器的Base64方法能够从文件API处理二进制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文