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

Add download as stream option to get objects as readable streams #72

Open
its-eli-z opened this issue Jul 6, 2022 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@its-eli-z
Copy link

Feature request

Is your feature request related to a problem? Please describe.

As a developer using the storage API, I want to have the ability to get the response body of the fetch request for an object as a stream instead of a final blob (current implementation).

Use cases:

  • To have memory-efficient server-side code for returning large objects to client requests, the server should not read the blob into memory and only pipe the stream to the HTTP response body.
  • When the server wants to return only parts of the object (according to some business rules). For example, there is an object which is a CSV file, and a server provides an export mechanism based on some filter coming as part of a client request. Ideally, the server would start to read rows from the large file, writing to the client response stream (filtered CSV) only the rows that matched the filter.

Describe the solution you'd like

Today's usage of the download function is like this:

const { data, error } = await supabase
  .storage
  .from(BUCKET)
  .download(PATH)

Data is the final blob, read into memory.

The download function could support an optional options object, initially with only one property, which defaults to false:

interface DownloadOptions {
  asStream?: boolean;
}

So now I can do (for example, stream directly to the client):

const { data, error } = await supabase
  .storage
  .from(BUCKET)
  .download(PATH, { asStream: true })

data.pipe(res)

Describe alternatives you've considered

Not using the supabase Storage API :(

A Suggestion for implementation

Per my understanding, it is easy to do with the standard Fetch API, which is supported in browsers, Node.JS (v17.5+), and deno.

The change should be pretty small, around here.

"Regular" downloads could return response.blob() from the fetch promise result (see docs)

Stream downloads calls could just return the response.body from the fetch promise result (see docs).

Another option is to have a separate downloadAsStream function, leaving the download stream always returning a blob.

I would be happy to help with that :)

@its-eli-z its-eli-z added the enhancement New feature or request label Jul 6, 2022
@its-eli-z its-eli-z changed the title Add download as stream option to get blobs as readable streams Add download as stream option to get objects as readable streams Jul 6, 2022
@jorgeAgoiz
Copy link

hi fellas, on what state is this issue? It would be a very good feature

@Bernix01
Copy link

Hello, any update on this?

@amhci
Copy link

amhci commented Mar 14, 2024

Would really love this. I'm developing an application that pulls ebooks files stored in a bucket in my server code and then sends that to the client. It would be great if I could stream the files instead of having to wait to download them fully on the server before sending to client!

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

No branches or pull requests

4 participants