Reputation: 825
Is there a way for me to detect, with javascript/jQuery when and if a file is currently being uploaded by the browser?
If not, how is this normally done? Or, is it only possible to detect if I'm using my own file uploader (as opposed to the browser's)?
Edit: not looking for someone to code this for me, just wondering what the "normal" methodology is so I can learn up. Google hasn't really helped in this (rare) case.
Upvotes: 1
Views: 1949
Reputation: 5428
If you're using an XHR as part of your upload progress, xhr.upload.addEventListener('loadstart', function () { ... })
will be called when the upload begins, and the check for completion is the same as any other XHR:
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
// Upload complete
}
};
More info about uploading with XHR can be found here: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/upload
JSFiddle sample: https://jsfiddle.net/Hatchet/dxyxdw1d/1/
Upvotes: 2