0

In JavaScript I am using fetch() to download large files.

Is there a way to get a download progress indicator while using fetch(), like a percentage or number of bytes downloaded?

Raed
  • 519
  • 1
  • 6
  • 23
  • 3
    Since `fetch` returns a promise, I doubt it. Promises don't have any concept of progress. – Felix Kling Dec 17 '16 at 23:08
  • 1
    Duplicate? [Progress indicators for fetch?](http://stackoverflow.com/q/35711724/218196) . [This answer talks about downloads](http://stackoverflow.com/a/35712094/218196). – Felix Kling Dec 17 '16 at 23:08
  • The answer seems outdated, and not working. – Raed Dec 17 '16 at 23:33
  • 1
    @RaedCHAMMAM _"Is there a way to get a download progress indicator while using `fetch()`, like a percentage or number of bytes downloaded?"_ Yes. Use `Response.body.getReader()`, `TextDecoder`. See [How to solve Uncaught RangeError when download large size json](http://stackoverflow.com/questions/39959467/how-to-solve-uncaught-rangeerror-when-download-large-size-json) – guest271314 Dec 17 '16 at 23:38
  • 1
    @RaedCHAMMAM Does the linked Answer resolve present Question? – guest271314 Dec 17 '16 at 23:45
  • @FelixKling _"Since fetch returns a promise, I doubt it. Promises don't have any concept of progress."_ `Response.body` has a `.getReader()` method that returns a `ReadableStream` which can be utilized to read the bytes of `Response.body` as a stream. Together with `TextDecoder`, it is possible to read the progress of `Response.body` as the stream is occurring. – guest271314 Dec 17 '16 at 23:46
  • 2
    @guest271314: yep, I learned about it from the other question. I'm still right about the promise part though ;) – Felix Kling Dec 18 '16 at 00:30

0 Answers0