简体   繁体   English

服务:亚马逊S3; 状态码:404; 错误代码:NoSuchBucket; 从 IBM Cloud Object Storage 获取文件时遇到问题

[英]Service: Amazon S3; Status Code: 404; Error Code: NoSuchBucket; Trouble getting a file from IBM Cloud Object Storage

I am trying to get a file from a bucket in IBM cloud object storage.我正在尝试从 IBM 云对象存储中的存储桶中获取文件。 For this, first I am trying to read all the available files in a bucket.为此,首先我尝试读取存储桶中的所有可用文件。

private static List<String> listBuckets(AmazonS3 cosClient) {
    final List<Bucket> bucketList = cosClient.listBuckets();
    List<String> bucketNames = new ArrayList<String>();
    for (final Bucket bucket : bucketList) {
        bucketNames.add(bucket.getName());
    }
    return bucketNames;
}

public InputStream getCOSFile(AmazonS3 cosClient, String bucketName, String objectName){
    List<String> bucketNames = listBuckets(cosClient);
    if (bucketNames.contains(bucketName)){
        LOGGER.info(bucketName+" exists");
        getBucketContentsV2(cosClient, bucketName, 2);
       }

Here, I get the message bucketName exists from within the if block.在这里,我从 if 块中获取消息 bucketName 存在。 Also, the bucket does exist in my cloud account.此外,存储桶确实存在于我的云帐户中。 But, getBucketContentsV2 gives me this error message: "The specified bucket does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchBucket; Request ID: xxxxx)但是,getBucketContentsV2 给了我这个错误消息:“指定的存储桶不存在。(服务:Amazon S3;状态代码:404;错误代码:NoSuchBucket;请求 ID:xxxxx)

Here's the method getBucketContentsV2, almost exactly as in the IBM cloud doc tutorials.这是 getBucketContentsV2 方法,几乎​​与 IBM 云文档教程中的一样。

public static void getBucketContentsV2(AmazonS3 cosClient, String bucketName, int maxKeys) {
    System.out.printf("Retrieving bucket contents (V2) from: %s\n", bucketName);

    boolean moreResults = true;
    String nextToken = "";

    while (moreResults) {
        ListObjectsV2Request request = new ListObjectsV2Request()
                .withBucketName(bucketName)
                .withMaxKeys(maxKeys)
                .withContinuationToken(nextToken);

        ListObjectsV2Result result = cosClient.listObjectsV2(request);
        for(S3ObjectSummary objectSummary : result.getObjectSummaries()) {
            System.out.printf("Item: %s (%s bytes)\n", objectSummary.getKey(), objectSummary.getSize());
        }

        if (result.isTruncated()) {
            nextToken = result.getNextContinuationToken();
            System.out.println("...More results in next batch!\n");
        }
        else {
            nextToken = "";
            moreResults = false;
        }
    }
    System.out.println("...No more results!");
}

I also tried retrieving all files in a bucket with V1 code in the docs, and get the same NoSuchBucket error.我还尝试在文档中使用 V1 代码检索存储桶中的所有文件,并得到相同的 NoSuchBucket 错误。

Here's the implementation of that method:这是该方法的实现:

public static void listBuckets(AmazonS3 cosClient, String bucketName) {
    System.out.printf("Retrieving bucket contents from: %s\n", bucketName);
    ObjectListing objectListing = cosClient.listObjects(new ListObjectsRequest().withBucketName(bucketName));
    for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        System.out.printf("Item: %s (%s bytes)\n", objectSummary.getKey(), objectSummary.getSize());
    }
    System.out.println();
}

So I have tried this code to replicate the error.所以我尝试了这段代码来复制错误。 I was able to list objects in the bucket.我能够列出存储桶中的对象。 My first guest would be a configuration error.我的第一个客人是配置错误。

String bucketName = "<BUCKET_NAME>";  // eg my-unique-bucket-name
String newBucketName = "<NEW_BUCKET_NAME>"; // eg my-other-unique-bucket-name
String apiKey = "<API_KEY>"; // eg "W00YiRnLW4k3fTjMB-oiB-2ySfTrFBIQQWanc--P3byk"
String serviceInstanceId = "<SERVICE_INSTANCE_ID"; // eg "crn:v1:bluemix:public:cloud-object-storage:global:a/3bf0d9003abfb5d29761c3e97696b71c:d6f04d83-6c4f-4a62-a165-696756d63903::"
String endpointUrl = "https://s3.us-south.cloud-object-storage.appdomain.cloud"; // this could be any service endpoint

Probably the endpointUrl is misconfigured.可能endpointUrl配置错误。 When you are getting the endpoint follow these steps:获取端点时,请执行以下步骤:

  1. Select the Endpoints menu from left从左侧选择端点菜单
  2. Select your Resiliency option.选择您的弹性选项。 Mine was Regional我的是区域性的
  3. Select your Region选择您的地区
  4. Copy the public endpoint.复制公共端点。

Mine was like this: s3.eu-de.cloud-object-storage.appdomain.cloud我的是这样的: s3.eu-de.cloud-object-storage.appdomain.cloud

暂无
暂无

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

相关问题 AWS S3 Java 拒绝访问服务:Amazon S3; 状态码:403; 错误代码:拒绝访问; - AWS S3 Java Access Denied Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; 访问被拒绝(服务:Amazon S3;状态代码:403;错误代码:AccessDenied;请求 ID:xxxxxxxxxxxxx) - Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: xxxxxxxxxxxxx) com.amazonaws.services.s3.model.AmazonS3Exception:Forbidden(Service:Amazon S3; Status Code:403; Error Code:403 Forbidden; Request ID:XXXXXXXX) - com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: XXXXXXXX) 如何解决 AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null) 使用 java - How to resolve AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: null) using java 如何在我的春季启动代码中处理Amazon S3存储桶的404错误 - How to handle 404 error for amazon s3 bucket in my spring boot code 尝试将文件上传到 Amazon S3 时返回错误代码 400 - Error code 400 returns when trying to upload file to Amazon S3 如何根据用户输入检查Amazon S3云存储中文本文件存储中的单词? - how to check for word in text file store in amazon s3 cloud storage against user input? Web服务https状态码404 - Web service https status code 404 运行上传文件代码时出现HTTP状态404错误 - HTTP Status 404 Error when Running Upload File Code Spring Cloud AWS代码未找到S3文件 - Spring Cloud AWS code not finding S3 File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM