1

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.

2
  • Is this a file upload as part of a form, or an xmlhttprequest (or the jquery equivalent cruft) upload? Commented Aug 23, 2016 at 1:55
  • This would be an upload via a form input file field. Commented Aug 23, 2016 at 2:05

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.