save image

This commit is contained in:
José Henrique 2023-09-28 22:53:09 -03:00
parent 4535ed5cf6
commit 6d8ec28dbb
1 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,17 @@ async fn load_big_image() -> Result<NamedFile> {
Ok(NamedFile::open(real_path)?)
}
#[post("/image/save-big-image")]
async fn save_big_image(image_data: web::Bytes) -> Result<HttpResponse> {
// Write bytes to file
std::fs::write("image.png", &image_data).unwrap();
// Return the blurred image bytes
Ok(HttpResponse::Ok()
.content_type("application/json")
.body("{\"status\": 200}"))
}
#[post("/image/blur")]
async fn blur_image(image_data: web::Bytes, req: HttpRequest) -> Result<HttpResponse> {
// Load the image from the incoming bytes
@ -61,7 +72,9 @@ async fn main() -> std::io::Result<()> {
.service(hello)
.service(load_small_image)
.service(load_big_image)
.service(save_big_image)
.service(blur_image)
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
})
.bind(("0.0.0.0", 5000))?
.run()