Fetch: How to monitor the 'progress' of the upload?

Created on 20 Sep 2015  Â·  7Comments  Â·  Source: github/fetch

use XMLHttpRequest, i listener 'progress', as below:

var XHR = new XMLHttpRequest();
XHR.upload.addEventListener("progress", function(e) {
  if (e.lengthComputable) {      
    var percentComplete = Math.round(e.position * 100 / e.total);
    console.log(percentComplete);
  }
}, false);

How do this with fetch ?

Most helpful comment

@domenic I don't understand how to use that snippet to monitor upload progress - in the spec I can only see streams for the response object, not the request object…

All 7 comments

Monitoring progress is not a feature of the Fetch API. Using XMLHttpRequest is the best way for now.

Bonus tip! You can use the triple back tick ``` to format code blocks in comment fields:
https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown

Did it plan to include it in the final specs?

It is already included in the spec, in a different form; please see the above linked gist for how you can translate from the new form to the old form.

ok, thanks you!

ok. i got it. thanks much.

@domenic I don't understand how to use that snippet to monitor upload progress - in the spec I can only see streams for the response object, not the request object…

Was this page helpful?
0 / 5 - 0 ratings

Related issues

huanghaiyang picture huanghaiyang  Â·  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  Â·  4Comments

poppinlp picture poppinlp  Â·  4Comments

codeashian picture codeashian  Â·  3Comments

mmocny picture mmocny  Â·  3Comments