gpt4 book ai didi

java - aws java sdk 未返回所有文件夹

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:48 25 4
gpt4 key购买 nike

正在运行

$ aws s3 ls s3://mybucket/myfolder/subfolder/monitor/

它正在返回我期望的所有文件。我已正确设置权限和凭据。然后我写了一些java代码:

public class S3Sample {
public static void main(String[] args) throws IOException {
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}

AmazonS3 s3 = new AmazonS3Client(credentials);
try {

ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
.withBucketName("mybucket"));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(objectSummary.getKey());
}

} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which means your request made it "
+ "to Amazon S3, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with S3, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}

}

代码正在打印 mybucket/myfolder/subfolder 中的内容,但在监视器中没有打印任何内容(并且缺少其他子目录)。我没有看到任何错误。如何诊断我看不到更多文件的原因。我显然拥有文件夹的权限并且凭据正在运行。任何建议都有帮助。谢谢!

最佳答案

只是一种猜测,但也许所有结果都不适合一个响应。看看是否ObjectListing#getNextMarker不为空。

关于java - aws java sdk 未返回所有文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24152486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com