How do i download stream file with filename by ByteStream #1741
-
i use ByteStream to download sftp file(ssh2 framework), but i can't special filename to download file, how to specify filename, please help me(i can't find other framework to download stream file😭)。 this is my example:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
For the browser to pop up a dialog with a filename, you need to set the
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. |
Beta Was this translation helpful? Give feedback.
-
i try it, thank u @SergioBenitez |
Beta Was this translation helpful? Give feedback.
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: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.