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

标签 java amazon-web-services amazon-s3

正在运行

$ 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/

相关文章:

amazon-web-services - 登录 Elastic Mapreduce 的最佳实践 - AWS

amazon-web-services - AWS 上的 Titan - 防止边缘和顶点丢失

javascript - 在 Typescript 中如何在绑定(bind)类型安全的同时 promise 一个函数?

logging - 将heroku日志发送到s3

java - AWS S3 Java SDK 不将文件复制到文件夹

java - 在 SWT 中,事件以什么顺序传递给小组件及其子组件

java - 如何从 Spring 环境自动生成 postman 集合

amazon-web-services - 如何在iam策略terraform中编写条件?

java - 使用 Eclipse 中的 Wildfly 8

java - 将嵌套的 For 循环转换为流