Skip to content

Instantly share code, notes, and snippets.

@fgblanch
Created July 19, 2013 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgblanch/6038699 to your computer and use it in GitHub Desktop.
Save fgblanch/6038699 to your computer and use it in GitHub Desktop.
Iterating through objects in a s3 folder
AmazonS3 s3 = new AmazonS3Client(new PropertiesCredentials(MyClass.class.getResourceAsStream("AwsCredentials.properties")));
String s3Key = "folder1/folder2";
String bucketName = Constantes.S3_BUCKET;
String key = s3Key +"/input_chopped/";
ObjectListing current = s3.listObjects(new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(key));
boolean siguiente = true;
while (siguiente) {
siguiente &= current.isTruncated();
contador += current.getObjectSummaries().size();
for (S3ObjectSummary objectSummary : current.getObjectSummaries()) {
S3Object object = s3.getObject(new GetObjectRequest(bucketName, objectSummary.getKey()));
System.out.println(object.getKey());
}
current=s3.listNextBatchOfObjects(current);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment