fix incomplete object list
This commit is contained in:
parent
58151024f1
commit
6ac1e7c7ab
1 changed files with 21 additions and 6 deletions
|
@ -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,6 +82,14 @@ 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();
|
||||||
|
boolean nextbatch = false;
|
||||||
|
while (result.isTruncated() || !nextbatch) {
|
||||||
|
if (nextbatch) {
|
||||||
|
result = s3client.listNextBatchOfObjects (result);
|
||||||
|
objects = result.getObjectSummaries();
|
||||||
|
} else {
|
||||||
|
nextbatch = true;
|
||||||
|
}
|
||||||
for (S3ObjectSummary os : objects) {
|
for (S3ObjectSummary os : objects) {
|
||||||
filename = os.getKey().split("/");
|
filename = os.getKey().split("/");
|
||||||
object.add(filename[treelevel]);
|
object.add(filename[treelevel]);
|
||||||
|
@ -86,6 +97,8 @@ public class ObjectSelect extends AppCompatActivity {
|
||||||
//i++;
|
//i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Name = new ArrayList<String>(object);
|
Name = new ArrayList<String>(object);
|
||||||
object.clear();
|
object.clear();
|
||||||
//Img.add(R.drawable.unknownfile);
|
//Img.add(R.drawable.unknownfile);
|
||||||
|
@ -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());
|
||||||
|
|
Loading…
Reference in a new issue