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

Addon for upload progress #199

Closed
kibertoad opened this issue Aug 28, 2023 · 5 comments
Closed

Addon for upload progress #199

kibertoad opened this issue Aug 28, 2023 · 5 comments

Comments

@kibertoad
Copy link

Is it possible to have something similar to https://github.com/elbywan/wretch#progress- for the upload progress?

This is for implementing upload progress indicators.
Something like this: https://github.com/axios/axios/blob/main/examples/upload/index.html

@laurismikals
Copy link

laurismikals commented Aug 28, 2023

Currently it only reports once - at the end of the upload - which is not ideal.

	wretch
		.addon(ProgressAddon())
		.formData({ file, filePath })
		.url('/upload-file')
		.post()
		.progress((loaded, total) => {
			console.log({ loaded, total }) // For a 800 KB file currently it reports only once when the file has uploaded  - { loaded: 58, total: 58 }
		})
		.json()

@elbywan
Copy link
Owner

elbywan commented Sep 12, 2023

Hey @kibertoad,

Is it possible to have something similar to https://github.com/elbywan/wretch#progress- for the upload progress?

Unfortunately no, this is a limitation of using fetch :/.

See: #154

@kibertoad
Copy link
Author

@elbywan document linked in that issue states that everything but firefox support it, and firefox has miniscule market share. is it still too early for this feature?

@elbywan
Copy link
Owner

elbywan commented Sep 13, 2023

Hey @kibertoad,

I think the link you are referring to is about the Request.body field and yeah Firefox does not support that.

In addition, Safari does not support upload streaming which is a bit different (passing the body as a readable stream to fetch):

fetch("/", {
  method: 'POST',
  headers: {'Content-Type': 'text/plain'},
  body: stream, // a previously constructed stream
  duplex: 'half',
});

Gives:

notsupportederror: ReadableStream uploading is not supported

is it still too early for this feature?

Yes I think it would be better to wait or proper support - and a proper API.

@kibertoad
Copy link
Author

There is whatwg/fetch#607, apparently.

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

No branches or pull requests

3 participants