fix incomplete object list

This commit is contained in:
Page Asgardius 2022-09-03 14:37:07 -07:00
parent 58151024f1
commit 6ac1e7c7ab

View file

@ -19,6 +19,8 @@ import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions; import com.amazonaws.services.s3.S3ClientOptions;
import com.amazonaws.services.s3.model.Bucket; import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; 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.ListObjectsV2Result;
import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3Object;
@ -68,9 +70,10 @@ public class ObjectSelect extends AppCompatActivity {
public void run() { public void run() {
try { try {
//Your code goes here //Your code goes here
List<Bucket> buckets = s3client.listBuckets(); //List<Bucket> buckets = s3client.listBuckets();
ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(prefix).withMaxKeys(2000);
//List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/"); //List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/");
ListObjectsV2Result result = s3client.listObjectsV2(bucket, "/"); ObjectListing result = s3client.listObjects(orequest);
//System.out.println(objects); //System.out.println(objects);
//This convert bucket list to an array list //This convert bucket list to an array list
Img = new ArrayList<String>(); Img = new ArrayList<String>();
@ -79,11 +82,21 @@ public class ObjectSelect extends AppCompatActivity {
//System.out.println("Buckets:"); //System.out.println("Buckets:");
//int i=0; //int i=0;
List<S3ObjectSummary> objects = result.getObjectSummaries(); List<S3ObjectSummary> objects = result.getObjectSummaries();
for (S3ObjectSummary os : objects) { boolean nextbatch = false;
filename = os.getKey().split("/"); while (result.isTruncated() || !nextbatch) {
object.add(filename[treelevel]); 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<String>(object); Name = new ArrayList<String>(object);
@ -108,6 +121,8 @@ public class ObjectSelect extends AppCompatActivity {
i++; i++;
} }
/*for (Bucket bucket : buckets) { /*for (Bucket bucket : buckets) {
//i++; //i++;
//System.out.println(bucket.getName()); //System.out.println(bucket.getName());