Are Google Chrome Base64 methods capable of handling binary data from the File API?

…衆ロ難τιáo~ 提交于 2019-12-13 16:17:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!