upload.rs
627 Bytes
use actix_web::{Error, HttpResponse, web};
use anyhow::Result;
use futures::stream::StreamExt;
use async_std::{fs::OpenOptions, io::WriteExt};
use uuid::Uuid;
pub async fn upload(mut body: web::Payload) -> Result<HttpResponse, Error>
{
let mut output = OpenOptions::new();
output . create(true)
. write(true);
let mut output = output
. open(format!("/tmp/upload_{}", Uuid::new_v4()))
. await
. unwrap();
while let Some(item) = body.next().await {
output.write_all(&item?).await.unwrap();
}
Ok(HttpResponse::Ok().finish())
}