WIP create a handler to download a file chunk by chunk.

This commit is contained in:
Florian THIERRY
2026-07-14 00:13:47 +02:00
parent 850dbca6cf
commit c24df944c5
14 changed files with 413 additions and 83 deletions
-15
View File
@@ -1,6 +1,5 @@
extern crate core;
use crate::user::handler::{create_new_user, delete_by_id, get_all_users, initialise, login, update_user, update_user_password};
use crate::user::validator::validator;
use actix_web::web::ServiceConfig;
use actix_web::{get, web, HttpResponse, Responder};
@@ -15,20 +14,6 @@ async fn health() -> impl Responder {
}
pub fn init(cfg: &mut ServiceConfig) {
cfg.service(health)
.service(health)
.service(initialise)
.service(login)
.service(
web::scope("")
.wrap(HttpAuthentication::bearer(validator))
.service(create_new_user)
.service(update_user)
.service(update_user_password)
.service(get_all_users)
.service(delete_by_id)
);
cfg.default_service(web::to(not_found));
}
+17
View File
@@ -0,0 +1,17 @@
use actix_web::{get, HttpResponse};
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};
use futures_util::stream::StreamExt;
#[get("/download")]
pub async fn download_file() -> HttpResponse {
HttpResponse::Ok()
.content_type("application/octet-stream")
.streaming(async_stream::stream! {
let file = File::open("/home/florian/Video/2019-06-02 17-09-30.flv").await.expect("Failed to open file");
let mut stream = FramedRead::new(file, BytesCodec::new());
while let Some(chunk) = stream.next().await {
yield chunk.map(|bytes| bytes.freeze());
}
})
}
+1
View File
@@ -1 +1,2 @@
pub mod handler;
pub mod video_format_content_type_mapper;