My code creates an XHR and sets its upload.onprogress callback to increment a counter. The problem is that, when I upload a 15 MB file (which takes over 10 seconds to upload), the onprogress callback fires only twice.
From this other question I learned that, according to the spec, a task should be queued to fire a progress event "about every 50ms or for every byte transmitted, whichever is least frequent." So, I expect to see many more events than just two.
I am testing on Chrome on Linux. In case it is relevant, the XHR code is run inside an iframe proxy (to communicate across domains).
var numProgressEventsFired = 0;
xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(e) {
numProgressEventsFired += 1;
};
xhr.onload = function() {
console.info("numProgressEventsFired: " + numProgressEventsFired); // Always 2.
if (xhr.status === 200) {
console.info("Upload completed.");
} else {
console.error("Upload failed. Error code: " + xhr.status);
}
};
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
...
xhr.sendAsBinary(binaryDataMessage);