mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
v3 examples (#364)
This commit is contained in:
@ -10,8 +10,7 @@ repository = "https://github.com/actix/examples"
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
actix-multipart = "0.2.0"
|
||||
actix-rt = "1.0.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-multipart = "0.3"
|
||||
actix-web = "3"
|
||||
futures = "0.3.1"
|
||||
sanitize-filename = "0.2"
|
||||
|
@ -10,10 +10,12 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
|
||||
let content_type = field.content_disposition().unwrap();
|
||||
let filename = content_type.get_filename().unwrap();
|
||||
let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename));
|
||||
|
||||
// File::create is blocking operation, use threadpool
|
||||
let mut f = web::block(|| std::fs::File::create(filepath))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Field in turn is stream of *Bytes* object
|
||||
while let Some(chunk) = field.next().await {
|
||||
let data = chunk.unwrap();
|
||||
@ -38,7 +40,7 @@ fn index() -> HttpResponse {
|
||||
HttpResponse::Ok().body(html)
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
|
||||
std::fs::create_dir_all("./tmp").unwrap();
|
||||
|
Reference in New Issue
Block a user