folder delete

This commit is contained in:
Page Asgardius 2022-09-10 13:21:06 -07:00
parent 3413ac4755
commit 77a9367e31

View file

@ -26,6 +26,7 @@ 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.DeleteObjectRequest; 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.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ListObjectsV2Request; import com.amazonaws.services.s3.model.ListObjectsV2Request;
@ -373,10 +374,10 @@ public class ObjectSelect extends AppCompatActivity {
//Your code goes here //Your code goes here
//List<Bucket> buckets = s3client.listBuckets(); //List<Bucket> buckets = s3client.listBuckets();
if (folder) { if (folder) {
ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(2); ListObjectsRequest orequest = new ListObjectsRequest().withBucketName(bucket).withPrefix(object).withMaxKeys(8000);
//List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/"); //List<S3Object> objects = (List<S3Object>) s3client.listObjects(bucket, "/");
ObjectListing result = s3client.listObjects(orequest); ObjectListing result = s3client.listObjects(orequest);
ArrayList<String> object = new ArrayList<String>(); ArrayList<String> objectl = new ArrayList<String>();
List<S3ObjectSummary> objects = result.getObjectSummaries(); List<S3ObjectSummary> objects = result.getObjectSummaries();
boolean nextbatch = false; boolean nextbatch = false;
while (result.isTruncated() || !nextbatch) { while (result.isTruncated() || !nextbatch) {
@ -387,16 +388,18 @@ public class ObjectSelect extends AppCompatActivity {
nextbatch = true; nextbatch = true;
} }
for (S3ObjectSummary os : objects) { for (S3ObjectSummary os : objects) {
object.add(os.getKey()); objectl.add(os.getKey());
//i++; //i++;
} }
} }
//System.out.println(object); //System.out.println(object);
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket).withKeys(objectl.toArray(new String[0]));
s3client.deleteObjects(deleteObjectsRequest);
} else { } else {
DeleteObjectRequest deleteObjectRequest =new DeleteObjectRequest(bucket, object); DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, object);
s3client.deleteObject(deleteObjectRequest); s3client.deleteObject(deleteObjectRequest);
} }