I want to send image to the Frontend with a path /images/{pic_name}. Here is the actix web way
.service(web::resource("/images/{pic_name}").route(web::get().to(images)))
And here the fuction images:
async fn images(req: HttpRequest, info: web::Path<Info>) -> Result<HttpResponse, Error> {
Ok(HttpResponse::build(StatusCode::OK)
.content_type("image/jpeg")
.body("images/".to_string() + &info.pic_name + &".jpeg"))
}
The Folder structure is:
images -| -> inside jpeg and webp
src -| -> inside the source files rs
Cargo.toml -|
My Cargo toml is
[dependencies]
actix-web = "4.0.0-beta.5"
actix-service = "2.0.0-beta.5"
actix-files = "0.6.0-beta.8"
actix-rt = "2.4.0"
Question: What is the way to send an image like the nodejs on express sendFile way,
res.sendFile(path.join(__dirname, `/assets/images/${req.params.picName}.${acceptedHeader}`));
Edit: maybe the path is wrong or something, cause i get a 200 and always the image is broken.