WIP create a handler to download a file chunk by chunk.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user