问题
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