Skip to content

How do i download stream file with filename by ByteStream #1741

Answered by SergioBenitez
Jrohy asked this question in Questions
Discussion options

You must be logged in to vote

For the browser to pop up a dialog with a filename, you need to set the Content-Disposition header in the response. See MDN's docs. It looks like this:

Content-Disposition: attachment; filename="filename.jpg"

See the custom responder's section of the guide for how to easily create a responder with this header.

P.S: Your implementation is incorrect as it makes use of blocking I/O. The majority of your code would be unnecessary if the stream was asynchronous, which it must be to be used in an async context without spawn_blocking. If it was, you could use ReaderStream::one and remove the inefficient buffering in your implementation.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Jrohy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants