1
0
mirror of https://github.com/actix/examples synced 2025-06-27 09:29:02 +02:00

update multipart examples to use derive macro

This commit is contained in:
Rob Ede
2023-02-26 21:56:55 +00:00
parent 9b77b033b0
commit 080db60175
10 changed files with 309 additions and 241 deletions

View File

@ -71,14 +71,16 @@ impl Client {
async fn upload_and_remove(&self, file: TempFile, key_prefix: &str) -> UploadedFile {
let uploaded_file = self.upload(&file, key_prefix).await;
file.delete_from_disk().await;
tokio::fs::remove_file(file.file.path()).await.unwrap();
uploaded_file
}
async fn upload(&self, file: &TempFile, key_prefix: &str) -> UploadedFile {
let filename = file.name();
let key = format!("{key_prefix}{}", file.name());
let s3_url = self.put_object_from_file(file.path(), &key).await;
let filename = file.file_name.as_deref().expect("TODO");
let key = format!("{key_prefix}{filename}");
let s3_url = self
.put_object_from_file(file.file.path().to_str().unwrap(), &key)
.await;
UploadedFile::new(filename, key, s3_url)
}