Created
July 19, 2013 12:10
-
-
Save fgblanch/6038699 to your computer and use it in GitHub Desktop.
Iterating through objects in a s3 folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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