From 6ac1e7c7ab359afa76b159dd87813b2a6ab044d9 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sat, 3 Sep 2022 14:37:07 -0700 Subject: [PATCH] fix incomplete object list --- .../page/s3manager/ObjectSelect.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index f4cca58..923e8ab 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -19,6 +19,8 @@ import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.S3ClientOptions; import com.amazonaws.services.s3.model.Bucket; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; +import com.amazonaws.services.s3.model.ListObjectsRequest; +import com.amazonaws.services.s3.model.ListObjectsV2Request; import com.amazonaws.services.s3.model.ListObjectsV2Result; import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.S3Object; @@ -68,9 +70,10 @@ public class ObjectSelect extends AppCompatActivity { public void run() { try { //Your code goes here - List buckets = s3client.listBuckets(); + //List buckets = s3client.listBuckets(); + ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix).withMaxKeys(2000); //List objects = (List) s3client.listObjects(bucket, "/"); - ListObjectsV2Result result = s3client.listObjectsV2(bucket, "/"); + ObjectListing result = s3client.listObjects(orequest); //System.out.println(objects); //This convert bucket list to an array list Img = new ArrayList(); @@ -79,11 +82,21 @@ public class ObjectSelect extends AppCompatActivity { //System.out.println("Buckets:"); //int i=0; List objects = result.getObjectSummaries(); - for (S3ObjectSummary os : objects) { - filename = os.getKey().split("/"); - object.add(filename[treelevel]); + boolean nextbatch = false; + while (result.isTruncated() || !nextbatch) { + if (nextbatch) { + result = s3client.listNextBatchOfObjects (result); + objects = result.getObjectSummaries(); + } else { + nextbatch = true; + } + for (S3ObjectSummary os : objects) { + filename = os.getKey().split("/"); + object.add(filename[treelevel]); + + //i++; + } - //i++; } Name = new ArrayList(object); @@ -108,6 +121,8 @@ public class ObjectSelect extends AppCompatActivity { i++; } + + /*for (Bucket bucket : buckets) { //i++; //System.out.println(bucket.getName());