I thought these two pieces of code (they work in Chrome and Firefox) were supposed to do the same thing, but they behave in different ways. They send the binary contents of a file via an XmlHttpRequest
object.
Direct XHR send:
xhr.send(file);
Read file and send contents via XHR:
var reader = new FileReader();
reader.onload = function(event) {
xhr.send(event.target.result);
};
reader.readAsBinaryString(file);
File bytes sent do not match between requests (in the second one, the file is larger than in the first one, and the file gets corrupted).
I need to make the second option work.
Any ideas?