mirror of
https://github.com/actix/examples
synced 2025-02-02 09:39:03 +01:00
update rusoto_core = "0.43.0-beta.1" (#252)
This commit is contained in:
parent
691812f3f4
commit
007e194ad2
@ -11,8 +11,8 @@ futures = "0.3.1"
|
||||
actix-multipart = "0.2.0"
|
||||
actix-web = "2.0.0"
|
||||
actix-rt = "1.0.0"
|
||||
rusoto_s3 = "0.42.0"
|
||||
rusoto_core = "0.42.0"
|
||||
rusoto_s3 = "0.43.0-beta.1"
|
||||
rusoto_core = "0.43.0-beta.1"
|
||||
bytes = { version = "0.5", features = ["serde"] }
|
||||
serde = { version = "1.0.104", features=["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::rusoto_s3::S3;
|
||||
use rusoto_core::{ProvideAwsCredentials, Region, RusotoError};
|
||||
use rusoto_core::{Region, RusotoError, RusotoFuture};
|
||||
use rusoto_s3::{DeleteObjectRequest, PutObjectRequest, S3Client};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
@ -31,7 +31,7 @@ impl Client {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn put_object(&self, localfilepath: &str, key: &str) -> String {
|
||||
pub async fn put_object(&self, localfilepath: &str, key: &str) -> String {
|
||||
let mut file = std::fs::File::open(localfilepath).unwrap();
|
||||
let mut contents: Vec<u8> = Vec::new();
|
||||
file.read_to_end(&mut contents);
|
||||
@ -44,13 +44,13 @@ impl Client {
|
||||
let res = self
|
||||
.s3
|
||||
.put_object(put_request)
|
||||
.sync()
|
||||
.await
|
||||
.expect("Failed to put test object");
|
||||
|
||||
self.url(key)
|
||||
}
|
||||
|
||||
pub fn delete_object(&self, key: String) {
|
||||
pub async fn delete_object(&self, key: String) {
|
||||
let delete_object_req = DeleteObjectRequest {
|
||||
bucket: self.bucket_name.to_owned(),
|
||||
key: key.to_owned(),
|
||||
@ -60,7 +60,7 @@ impl Client {
|
||||
let res = self
|
||||
.s3
|
||||
.delete_object(delete_object_req)
|
||||
.sync()
|
||||
.await
|
||||
.expect("Couldn't delete object");
|
||||
}
|
||||
}
|
||||
|
@ -47,15 +47,15 @@ impl Tmpfile {
|
||||
}
|
||||
}
|
||||
|
||||
fn s3_upload_and_tmp_remove(&mut self, s3_upload_key: String) {
|
||||
self.s3_upload(s3_upload_key);
|
||||
async fn s3_upload_and_tmp_remove(&mut self, s3_upload_key: String) {
|
||||
self.s3_upload(s3_upload_key).await;
|
||||
self.tmp_remove();
|
||||
}
|
||||
|
||||
fn s3_upload(&mut self, s3_upload_key: String) {
|
||||
async fn s3_upload(&mut self, s3_upload_key: String) {
|
||||
let key = format!("{}{}", &s3_upload_key, &self.name);
|
||||
self.s3_key = key.clone();
|
||||
let url: String = Client::new().put_object(&self.tmp_path, &key.clone());
|
||||
let url: String = Client::new().put_object(&self.tmp_path, &key.clone()).await;
|
||||
self.s3_url = url;
|
||||
}
|
||||
|
||||
@ -107,11 +107,12 @@ pub async fn save_file(
|
||||
) -> Result<Vec<UplodFile>, Error> {
|
||||
let mut arr: Vec<UplodFile> = Vec::new();
|
||||
let mut iter = tmp_files.iter();
|
||||
let mut index = 0;
|
||||
// iterate over multipart stream
|
||||
|
||||
while let Some(item) = iter.next() {
|
||||
let mut tmp_file: Tmpfile = item.clone();
|
||||
tmp_file.s3_upload_and_tmp_remove(s3_upload_key.clone());
|
||||
tmp_file
|
||||
.s3_upload_and_tmp_remove(s3_upload_key.clone())
|
||||
.await;
|
||||
arr.push(UplodFile::from(tmp_file));
|
||||
}
|
||||
Ok(arr)
|
||||
@ -119,6 +120,6 @@ pub async fn save_file(
|
||||
|
||||
pub async fn delete_object(mut list: Vec<String>) {
|
||||
for key in list {
|
||||
Client::new().delete_object(key);
|
||||
Client::new().delete_object(key).await;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user