Added s3 creds and urls

This commit is contained in:
Franklin 2023-05-03 20:19:27 -04:00
parent 8963d21b9c
commit 002f420df9
2 changed files with 5 additions and 4 deletions

View File

@ -12,7 +12,6 @@ tokio = {version = "1.20.1", features = ["full"]}
chrono = "0.4.23" chrono = "0.4.23"
chrono-tz = "0.8" chrono-tz = "0.8"
reqwest = { version = "0.11.11", features = ["rustls-tls", "json", "blocking"], default-features = false } reqwest = { version = "0.11.11", features = ["rustls-tls", "json", "blocking"], default-features = false }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.88" serde_json = "1.0.88"
sqlx = { version = "0.6.0", features = [ "runtime-tokio-rustls", "postgres", "chrono", "uuid", "offline" ] } sqlx = { version = "0.6.0", features = [ "runtime-tokio-rustls", "postgres", "chrono", "uuid", "offline" ] }

View File

@ -1,6 +1,7 @@
use aws_sdk_s3::{ use aws_sdk_s3::{
error::SdkError, operation::put_object::PutObjectError, primitives::ByteStream, Client, error::SdkError, operation::put_object::PutObjectError, primitives::ByteStream, Client,
}; };
use uuid::Uuid;
pub async fn init_aws_client() -> Client { pub async fn init_aws_client() -> Client {
dotenvy::dotenv().expect("Failed loading env"); dotenvy::dotenv().expect("Failed loading env");
@ -10,13 +11,14 @@ pub async fn init_aws_client() -> Client {
pub async fn upload_image( pub async fn upload_image(
client: &Client, client: &Client,
realtor_id: Uuid,
file_name: String, file_name: String,
multipart: Vec<u8>, multipart: Vec<u8>,
) -> Result<String, SdkError<PutObjectError>> { ) -> Result<String, SdkError<PutObjectError>> {
let path = format!("jl-images/{file_name}"); let path = format!("realtor-images/{realtor_id}/{file_name}");
match client match client
.put_object() .put_object()
.bucket("jorge-ledesma-bucket") .bucket("realtor-lp-bucket")
.key(path.clone()) .key(path.clone())
.body(ByteStream::from(multipart)) .body(ByteStream::from(multipart))
.acl(aws_sdk_s3::types::ObjectCannedAcl::PublicRead) .acl(aws_sdk_s3::types::ObjectCannedAcl::PublicRead)
@ -24,7 +26,7 @@ pub async fn upload_image(
.await .await
{ {
Ok(_) => Ok(format!( Ok(_) => Ok(format!(
"https://jorge-ledesma-bucket.s3.us-east-2.amazonaws.com/{path}" "https://realtor-lp-bucket.s3.us-east-2.amazonaws.com/{path}"
)), )),
Err(error) => Err(error), Err(error) => Err(error),
} }