Add support for sending a file #112
prabirshrestha
started this conversation in
Ideas
Replies: 2 comments 8 replies
-
Converted to a discussion, as this is potentially a new handler / crate, specifically if the static file handler doesn't work for you. |
Beta Was this translation helpful? Give feedback.
3 replies
-
What is the recommended way to create an use async_fs::{self as fs, File};
#[trillium::async_trait]
pub trait SendFileConnExt {
async fn send_file<P: AsRef<Path>>(mut self, path: P) -> Self;
}
#[trillium::async_trait]
impl SendFileConnExt for Conn {
async fn send_file<P: AsRef<Path>>(mut self, path: P) -> Self {
let file = conn_try!(File::open(&path).await, self);
let metadata = conn_try!(fs::metadata(&path).await, self);
let len = metadata.len();
self.with_body(Body::new_streaming(file, Some(len)))
.with_status(200)
}
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been working on porting a tide app to use trillium and noticed that there is no way to send a single file. Closest I found was
StaticFileHandler
.I'm looking for an alternative for
Body::from_file()
.Beta Was this translation helpful? Give feedback.
All reactions