繁体   English   中英

AmazonS3 SDK:列出对象时拒绝访问

[英]AmazonS3 SDK: Access denied when Listing Objects

我正在尝试列出存储桶中的对象,但是当我尝试列出存储桶中的对象时一直被阻止。

但是,所有s3.list*命令都失败并显示以下错误。 如何从存储桶中的文件夹返回文件列表?

代码

LOGGER.info("tomorrowBucket: [{}]", tomorrowBucket);
if (s3.doesBucketExistV2(tomorrowBucket)) {
    LOGGER.info("made it");
    LOGGER.info("probably gonna fail");
    for (S3ObjectSummary summary : S3Objects.inBucket(s3, tomorrowBucket)) {
         LOGGER.info(" * " + summary.getKey() + "  " + "(size = " + summary.getSize() + ")");
     }
     LOGGER.info("made it past");
}

日志

  tomorrowBucket: [20200311]
 - made it
 - probably gonna fail

错误

     com.amazonaws.SdkClientException: Failed to parse XML document with handler class com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListObjectsV2Handler
...
    Caused by: org.xml.sax.SAXParseException; Premature end of file.

我在端点配置中指定了存储桶,而不是直接指向租户:

不正确

hs3Client.setEndpoint("bucketname.europe.hcp.example.com");

正确的

// Set up the service point to be the tenant in HCP.
hs3Client.setEndpoint("europe.hcp.example.com");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM