Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload progress? #21

Closed
radubrehar opened this issue Feb 20, 2015 · 14 comments
Closed

upload progress? #21

radubrehar opened this issue Feb 20, 2015 · 14 comments

Comments

@radubrehar
Copy link

Is there any way I can attach a progress listener to the xhr.upload object used in fetch?

xhr.upload.addEventListener('progress', function(){ ... })

since I use fetch to upload files (with FormData), I would find this very useful.

I initially reported this at JakeChampion/fetch#89, and was suggested to have it reported here

@annevk
Copy link
Member

annevk commented Feb 20, 2015

The native fetch() API implemented by browsers does not use XMLHttpRequest underneath. The eventual API for progress is building something on https://streams.spec.whatwg.org/ which https://github.com/yutakahirano/fetch-with-streams/ is adding to fetch().

@cusspvz
Copy link

cusspvz commented Mar 30, 2017

The native fetch() API implemented by browsers does not use XMLHttpRequest underneath.

But yet, it does not mean it couldn't be pondered and proposed.

Native promises are not yet cancellable and/or progressed, so my proposal would be for a callback on the second argument object of fetch which would receive a ProgressEvent (which is already present because of XHR).

As a polyfill, it could be easily placed with the progress event listener as stated by the OP.

API Example:

aync fetchSometing ( form ) {
  const res = await fetch('/upload', {
    method: 'POST',
    body: form,
    progress: (e) => { console.log(`Progress: ${e.loaded/e.total}%`) }
  })
}

@ilan-schemoul
Copy link

So why @cusspvz's idea doesn't seem to have been taken in consideration ?
It seems a good idea to me.

@jakearchibald
Copy link
Collaborator

Discussion around fetch observation is over at #447.

@caub
Copy link

caub commented Apr 15, 2018

The discussion in #447 was more about fetch cancellation, now it's added in the spec with AbortController

For fetch upload progress, it would be great, that's the only missing thing compared to XHR

@annevk
Copy link
Member

annevk commented Apr 15, 2018

Ah, thanks for pinging this thread. Observation moved to #607. Hope that helps.

@oliverjanik
Copy link

Please reopen this issue. This is real world scenario on millions of websites daily. Fetch needs needs an upload progress. period. We've been stuck with the bad XHR API for decades now.

Yet, no one seems concerned that despite all the efforts and years of debates that went into fetch it does not deliver.

Can everyone on this committee stop treating it as a hot potato a deal with it.

@annevk
Copy link
Member

annevk commented Jun 8, 2018

There is no committee… And this issue is closed because there is a more focused issue around a concrete proposal towards addressing this.

@mindtonic
Copy link

@oliverjanik Use the .on('progress', ...... ) feature of Superagent. https://github.com/visionmedia/superagent

@oliverjanik
Copy link

No thanks, I like my batteries included.

@xgqfrms
Copy link

xgqfrms commented Oct 8, 2018

https://github.com/AnthumChris/fetch-progress-indicators

@oliverjanik
Copy link

@xgqfrms I only see download progress, where is upload progress ?

@annevk What proposal are you talking about? Can you post a link?

@annevk
Copy link
Member

annevk commented Feb 12, 2019

#21 (comment)

@TestPolygon
Copy link

TestPolygon commented Sep 17, 2019

It can be done if browsers will start support ReadableStream for Request object's body.

Currently there is only support of ReadableStream for Response object's body and you can use it for checking download progress.

They should implement that:
https://fetch.spec.whatwg.org/#bodyinit

Check your browser:
https://w3c-test.org/fetch/api/basic/request-upload.any.html

So, waiting for the browser support, in this case you even do not need something like this: #607

See also: #425

yutakahirano added a commit that referenced this issue Jun 23, 2020
# This is the 1st commit message:

# This is a combination of 23 commits.
# This is the 1st commit message:

Integrate CORP and COEP

This is part of the introduction of COEP
(whatwg/html#5454). The CORP check now takes
COEP into account. Also, responses coming from service workers
are checked.

# This is the commit message #2:

Update fetch.bs

Co-authored-by: Domenic Denicola <d@domenic.me>
# This is the commit message #3:

Update fetch.bs

Co-authored-by: Domenic Denicola <d@domenic.me>
# This is the commit message #4:

fix

# This is the commit message #5:

fix

# This is the commit message #6:

fix

# This is the commit message #7:

fix

# This is the commit message #8:

fix

# This is the commit message #9:

fix

# This is the commit message #10:

fix

# This is the commit message #11:

fix

# This is the commit message #12:

fix

# This is the commit message #13:

fix

# This is the commit message #14:

fix

# This is the commit message #15:

fix

# This is the commit message #16:

fix

# This is the commit message #17:

fix

# This is the commit message #18:

Update fetch.bs

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
# This is the commit message #19:

Update fetch.bs

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
# This is the commit message #20:

fix

# This is the commit message #21:

fix

# This is the commit message #22:

fix

# This is the commit message #23:

fix

# This is the commit message #2:

fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

10 participants