Fix duplicate file naming
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -169,13 +169,18 @@ async fn upload_image(
|
|||||||
warn!("File already exists: {:?}", full_path);
|
warn!("File already exists: {:?}", full_path);
|
||||||
|
|
||||||
let new_path = format!(
|
let new_path = format!(
|
||||||
"{:?}_{}.{:?}",
|
"{}/{}_{}.{}",
|
||||||
full_path.file_stem(),
|
full_path.parent().unwrap().to_str().unwrap(),
|
||||||
Utc::now(),
|
full_path.file_stem().unwrap().to_str().unwrap(),
|
||||||
|
Utc::now().timestamp(),
|
||||||
full_path
|
full_path
|
||||||
.extension()
|
.extension()
|
||||||
.expect("Uploaded file should have an extension")
|
.expect("Uploaded file should have an extension")
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
);
|
);
|
||||||
|
info!("Uploaded: {}", new_path);
|
||||||
|
|
||||||
let mut file = File::create(new_path).unwrap();
|
let mut file = File::create(new_path).unwrap();
|
||||||
file.write_all(&file_content).unwrap();
|
file.write_all(&file_content).unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user