Converting a BlobBuilder to string, in HTML5 Javascript

£可爱£侵袭症+ 提交于 2019-12-04 05:25:42

问题


          function blobToString(blob) {
             var reader = new FileReader();
             var d = "";
             reader.onloadend = function() {
                 d.callback(reader.result); 
                 console.log(reader.result);
             };
             reader.readAsText(blob);  
             return d;
         };

The above code does not work, but I guess my intentions are clear, I want to convert some binary data(WebKitBlobBuilder) to a string. Also the "console.log(reader.result);" doesn't display anything.


回答1:


Check out http://blog.ericzhang.com/state-of-binary-in-the-browser/ and his binary.js project.




回答2:


it should not be reader.onloadend but rather reader.onloaded

or try

reader.onload = function (e) {
e.target.result -> this is the data. 
}


来源:https://stackoverflow.com/questions/6886933/converting-a-blobbuilder-to-string-in-html5-javascript

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