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 example for sending a file via NamedFile/NamedFileBuilder #137

Closed
prabirshrestha opened this issue Sep 6, 2022 · 2 comments
Closed

Comments

@prabirshrestha
Copy link
Contributor

Examples include using static DirHandler but it would be good to have an example for NamedFile. I had to dig in the source code to see how it was used.

#[handler]
async fn get_file(req: &mut Request, res: &mut Response) -> anyhow::Result<()> {
  let path = "./file.txt";
  let file = NamedFile::open(path).await?;
  file.send(req.headers(), res).await;
  Ok(())
}

Also might be worth adding docs so can see an example without looking at the source code at https://docs.rs/axum/0.2.3/axum/response/struct.Redirect.html#.

@chrislearn
Copy link
Member

I appreciate if you can give a PR :)
Doc repository: https://github.com/salvo-rs/website

@chrislearn
Copy link
Member

Added fn send_file to Response.

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

No branches or pull requests

2 participants