I've been pulling my hair out for hours now with a question that has been asked a few times around here: I have binary data from a flash audio recorder, which I turn into a dataURL and then want to convert to a blob for upload. SO gave me several answers, which are all essentially the same:
- Blob from DataURL?
- How to convert dataURL to file object in javascript?
- Convert Data URI to File then append to FormData
I wrote the following code based on the above
var data = window.atob(dataURL.split(',')[1]);
var length = data.length;
var uInt8Array = new Uint8Array(length);
for (var i = 0; i < length; ++i) {
uInt8Array[i] = data.charCodeAt(i);
}
var myfile = new Blob([uInt8Array], {'type': 'audio/x-wav'});
This works perfectly in firefox nightly (20) and chrome 25, but chromium 20 keeps telling me the size of myfile is 19 bytes (when it should be several kb), and subsequent upload fails consistently. Is this a bug in chromium, or did I miss a doc saying it is not supported yet? Any alternative ideas?