From 77a9367e313816c386cad25e36d16fe74970740b Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sat, 10 Sep 2022 13:21:06 -0700 Subject: [PATCH] folder delete --- .../java/asgardius/page/s3manager/ObjectSelect.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index 79a9d84..a20e07f 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -26,6 +26,7 @@ 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.DeleteObjectRequest; +import com.amazonaws.services.s3.model.DeleteObjectsRequest; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ListObjectsV2Request; @@ -373,10 +374,10 @@ public class ObjectSelect extends AppCompatActivity { //Your code goes here //List buckets = s3client.listBuckets(); if (folder) { - ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(2); + ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(8000); //List objects = (List) s3client.listObjects(bucket, "/"); ObjectListing result = s3client.listObjects(orequest); - ArrayList object = new ArrayList(); + ArrayList objectl = new ArrayList(); List objects = result.getObjectSummaries(); boolean nextbatch = false; while (result.isTruncated() || !nextbatch) { @@ -387,16 +388,18 @@ public class ObjectSelect extends AppCompatActivity { nextbatch = true; } for (S3ObjectSummary os : objects) { - object.add(os.getKey()); + objectl.add(os.getKey()); //i++; } } //System.out.println(object); + DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket).withKeys(objectl.toArray(new String[0])); + s3client.deleteObjects(deleteObjectsRequest); } else { - DeleteObjectRequest deleteObjectRequest =new DeleteObjectRequest(bucket, object); + DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, object); s3client.deleteObject(deleteObjectRequest); }