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

getFile download progress #285

Open
henninghorn opened this issue Apr 30, 2021 · 2 comments
Open

getFile download progress #285

henninghorn opened this issue Apr 30, 2021 · 2 comments

Comments

@henninghorn
Copy link

henninghorn commented Apr 30, 2021

I found the undocumented (#220) progressHandler parameter you can use to display the progress when uploading a file.
I can't seem to find a way to track the progress of downloading a file.

This would be very useful when downloading large files.

Is it possible to get some sort of download progress currently in any way?

@j-berman
Copy link
Collaborator

j-berman commented May 2, 2021

Would need to implement this, just like uploadFile! The implementation would be similar to the uploadFile implementation described in #220 (PR's #221 and #225 show the code). Bandwidth to work on it is super slim at the moment unfortunately, but if you're willing, happy to review a PR and get it through!

Btw thank you for the PR to add it to the documentation for uploadFile. Touched it up a tiny bit here

@j-berman
Copy link
Collaborator

j-berman commented May 2, 2021

Technically you could also just get the file in byte ranges using the range param, and with each iteration, log the progress, like this:

const CHUNK_SIZE = 512 * 1024
let position = 0

while (position < file.size) {
   const chunkResult = await userbase.getFile({ databaseName, fileId, range: { start: position, end: position + CHUNK_SIZE } })
   const bytesRetrieved = position + chunkResult.file.size
   const progress = bytesRetrieved / file.size
   console.log(progress)
   
   // you'll also want to place the chunk in an array, and then rebuild the file when the while loop finishes

   position += CHUNK_SIZE
}

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

No branches or pull requests

2 participants