Eckstein Eckstein - 1 year ago 86
Javascript Question

Detect when file is uploading in browser

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.

Answer Source

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:

JSFiddle sample:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download