mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
Sanitize filename
This commit is contained in:
@ -14,3 +14,4 @@ actix-multipart = "0.2.0"
|
||||
actix-rt = "1.0.0"
|
||||
actix-web = "2.0.0"
|
||||
futures = "0.3.1"
|
||||
sanitize-filename = "0.2"
|
||||
|
@ -9,7 +9,7 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
|
||||
while let Ok(Some(mut field)) = payload.try_next().await {
|
||||
let content_type = field.content_disposition().unwrap();
|
||||
let filename = content_type.get_filename().unwrap();
|
||||
let filepath = format!("./tmp/{}", filename);
|
||||
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
|
||||
|
Reference in New Issue
Block a user