XHR progress events arrive too fast

I am doing direct upload to S3 using html form and ajax. It works well, files are uploaded. My problem is that progress events arrive too fast. Like all of them, up to 99.9% quit immediately at the beginning of the download.

var fd = new FormData(); // put data from the form to FormData object $.each( $('#upload-form').serializeArray(), function(i, field) { fd.append(field.name, field.value); }); // add selected filename to the form data var file = document.getElementById('path-to-file').files[0]; fd.append("file", file); var xhr = getXmlHttpRequest(); // cross-browser implementation xhr.upload.addEventListener("progress", function(e) { console.log(e.loaded + "/" + e.total); }); xhr.open('POST', 'http://mybucket.s3.amazonaws.com/', true); xhr.send(fd); 

also tried this way

 xhr.upload.onprogress = function(evt) { if (evt.lengthComputable) { console.log(e.loaded + "/" + e.total); } }; 

The browser history is as follows:

 [22:54:47.245] POST http://mybucket.s3.amazonaws.com/ [22:54:47.287] 359865/5680475 [22:54:47.330] 1408441/5680475 [22:54:47.408] 2751929/5680475 [22:54:47.449] 3964345/5680475 [22:54:47.509] 5668281/5680475 

and then nothing in the time it actually takes to download the 5M file.

If the browser information is current, I have Firefox 20.0.1

+6
source share

Source: https://habr.com/ru/post/943830/


All Articles