Skip to content

Commit

Permalink
print error from aws download
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewKiino committed Jun 4, 2021
1 parent b871c7d commit ec720f2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/cache/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub async fn download_from_s3(
let f_name = { filename.clone() };
let path_str = f_name.split("/").last().unwrap_or("");
let object_key = format!("{}/{}", prefix, path_str).to_string();
println!("Downloading {}/{}...", bucket, object_key);
let _bucket = bucket.clone();
let _object_key = object_key.clone();

println!("Downloading {}/{}...", bucket.clone(), object_key);

let request = GetObjectRequest {
bucket,
Expand All @@ -23,11 +26,19 @@ pub async fn download_from_s3(

let stream = s3_client.get_object(request).await;

let stream = stream?.body.take().expect("no body");
let mut output = match stream {
Ok(output) => output,
Err(error) => panic!(error.to_string()),
};

let stream = output.body.take().expect("No Content");

let mut body = stream.into_async_read();
let mut file = tokio::fs::File::create(filename).await.unwrap();
tokio::io::copy(&mut body, &mut file).await.ok();

println!("Downloaded {}/{}", _bucket, _object_key);

Ok(())
}

Expand Down

0 comments on commit ec720f2

Please sign in to comment.