Streaming file #192
-
Hi there, Would like to not used the Does this example is the correct way or do we have a better way ?
What should be your best way here ? Thx in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Try this: #[handler]
async fn hello(res: &mut Response) {
let file = tokio::fs::File::open("Cargo.toml").await.unwrap();
let stream = ReaderStream::new(file);
res.add_header(header::CONTENT_TYPE, "text/toml; charset=utf-8", true);
res.add_header(header::CONTENT_DISPOSITION, "attachment; filename=\"Cargo.toml\"", true);
res.streaming(stream);
} Or you can just use NamedFiile. |
Beta Was this translation helpful? Give feedback.
Try this:
Or you can just use NamedFiile.