1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

Sanitize filename

This commit is contained in:
Yuki Okushi
2020-05-19 13:48:49 +09:00
parent bc6f614f78
commit 7823473f8d
6 changed files with 6 additions and 3 deletions

View File

@ -12,7 +12,7 @@ async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
let filename = content_type
.get_filename()
.ok_or_else(|| actix_web::error::ParseError::Incomplete)?;
let filepath = format!("./tmp/{}", filename);
let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename));
let mut f = async_std::fs::File::create(filepath).await?;
// Field in turn is stream of *Bytes* object