Skip to content

is possible to server from a file imported using include_bytes! macro? #1929

Discussion options

You must be logged in to vote

NamedFile is used specifically to serve files from disk; there's no need to use it at the same time as include_bytes!.

Am I missing a possible solution? Or does this feature just not exist in Rocket?

Not only is it possible, it's intended to be pretty straightforward to do things like this! For example:

use rocket::http::ContentType;

#[get("/example.png")]
fn image() -> (ContentType, &'static [u8]) {
    (ContentType::PNG, include_bytes!("/tmp/example.png"))
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@johnyenter-briars
Comment options

Answer selected by johnyenter-briars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants