I'm using XMLHttpRequest (with jQuery) to get the upload progress of multiple files. By adding a "progress" event listener to the XMLHttpRequest object I can get event.loaded and event.total. Those variables give me the loaded and total bytes of all the files combined.
What I'd like to do is get the progress of each individual file, but from what I can see that information isn't available with XMLHttpRequest. Is that true?
I don't think this is even necessary, but here's my code:
var xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener('progress', function(event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
updateProgressBar(percent);
}, false);
}
return xhr;
If I can accomplish this with XMLHttpRequest that would be great. Any info on this would be appreciated.
$.post()or$.ajax()for each file you want to upload. That is the only way to get individualprogressevents for the files. Theprogressevent is related to the full XMLHttpRequest, it doesn't know or care about how many different "parts" or "files" are being uploaded; To the XHR, it's just binary. So to be able to know the progress of individual files you must only include a single file per request. - idbehold