Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b6127f6a6
|
||
|
|
8464401337
|
+28
-2
@@ -37,8 +37,7 @@ pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client {
|
|||||||
.force_path_style(true)
|
.force_path_style(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let client = aws_sdk_s3::Client::from_conf(s3_config);
|
aws_sdk_s3::Client::from_conf(s3_config)
|
||||||
client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -77,4 +76,31 @@ impl Labyrinth {
|
|||||||
Err(err) => Err(Error::Info(err.to_string())),
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn download(&self, file_key: &str) -> Result<Vec<u8>, Error> {
|
||||||
|
let client = init_client(&self.config).await;
|
||||||
|
|
||||||
|
match client
|
||||||
|
.get_object()
|
||||||
|
.bucket(self.config.bucket.clone())
|
||||||
|
.key(file_key)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
let body = response.body;
|
||||||
|
|
||||||
|
// Get the body as ByteStream
|
||||||
|
match body.collect().await {
|
||||||
|
Ok(data) => {
|
||||||
|
let bytes = data.into_bytes();
|
||||||
|
let raw_data = bytes.to_vec();
|
||||||
|
Ok(raw_data)
|
||||||
|
}
|
||||||
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user