Skip to content

Commit

Permalink
Rust: S3 ListObject v2 using pagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Dec 7, 2023
1 parent 61cf700 commit 4daaa5b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions rustv1/examples/s3/src/s3-service-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,25 @@ pub async fn delete_objects(client: &Client, bucket_name: &str) -> Result<Vec<St
// snippet-end:[rust.example_code.s3.basics.delete_objects]

// snippet-start:[rust.example_code.s3.basics.list_objects]
pub async fn list_objects(client: &Client, bucket_name: &str) -> Result<(), Error> {
let objects = client.list_objects_v2().bucket(bucket_name).send().await?;
println!("Objects in bucket:");
for obj in objects.contents() {
println!("{:?}", obj.key().unwrap());
pub async fn list_objects(client: &Client, bucket: &str) -> Result<(), Error> {
let mut response = client
.list_objects_v2()
.bucket(bucket.to_owned())
.max_keys(10) // In this example, go 10 at a time.
.into_paginator()
.send();

while let Some(result) = response.next().await {
match result {
Ok(output) => {
for object in output.contents() {
println!(" - {}", object.key().unwrap_or("Unknown"));
}
}
Err(err) => {
eprintln!("{err:?}")
}
}
}

Ok(())
Expand Down

0 comments on commit 4daaa5b

Please sign in to comment.