我在亚马逊上有一个S3存储桶,并试图以递归方式获取位于存储桶下的文件夹中的所有zip文件列表。
例如,我的zip文件的位置如下所示:
bucket1/${user1}/${date1}/abc.zip
bucket1/${user2}/${date2}/xyz.zip
bucket1/${user3}/${date3}/mno.zip
bucketName=bucket1
prefix=bucket1/
以下是我的代码:
final AmazonS3 amazonS3 = AmazonS3Utils.getAmazonS3Client();
final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName("bucket1")
.withPrefix("bucket1/");
ObjectListing current = amazonS3.listObjects(listObjectsRequest);
final List<S3ObjectSummary> keyList = current.getObjectSummaries();
while (current.isTruncated())
{
keyList.addAll(current.getObjectSummaries());
current = amazonS3.listNextBatchOfObjects(current);
}
keyList.addAll(current.getObjectSummaries());
for(S3ObjectSummary summary : keyList)
{
System.out.println(summary.getKey());
}
但我找回了一个清单。
我做错了吗?有没有办法以递归方式从存储桶中获取zip文件列表?
答案 0 :(得分:1)
我唯一能看到的就是获得与S3存储桶的连接。请尝试以下操作,这可能会有所帮助
AWSCredentials credentials = new BasicAWSCredentials(accessKeyId,secretAccessKey);
AmazonS3 s3Client = new AmazonS3Client(credentials);
ObjectListing objects = s3Client.listObjects(listobjectrequest);