【问题标题】:Creating bucket in Google Cloud Storage fails sometimes在 Google Cloud Storage 中创建存储桶有时会失败
【发布时间】:2019-04-01 12:33:21
【问题描述】:

我一直在尝试按照link 中的指南使用 Java 在 Google Cloud Storage 中创建存储桶。我有一个方法可以检查存储桶是否存在并返回一个布尔值,就像这样

private boolean checkIfBucketExists(String bucketName) {
   return storage.get(bucketName, Storage.BucketGetOption.fields()) != null
}

另外一种实际创建存储桶的方法,像这样

public Bucket createBucket(String bucketName) {
    if (checkIfBucketExists(bucketName)) {
      System.out.println("Bucket already exists!");
    }
    return storage.create(
        BucketInfo.newBuilder(bucketName)
            // See here for possible values: http://g.co/cloud/storage/docs/storage-classes
            .setStorageClass(StorageClass.COLDLINE)
            // Possible values: http://g.co/cloud/storage/docs/bucket-locations#location-mr
            .setLocation("eu")
            .build());
  }

当我创建一个存储桶时,它有时会有点奇怪。例如,我可以创建一个名为name-bucketbucket,但不能创建namebucket,即使我的项目中没有现有的namebucket。它给了我这个错误

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "myservice@project-id.iam.gserviceaccount.com does not have storage.buckets.get access to namebucket.",
    "reason" : "forbidden"
  } ],
  "message" : "myservice@project-id.iam.gserviceaccount.com does not have storage.buckets.get access to namebucket."
}

是否是这样,在 Google Cloud Storage 中,我无法使用其他用户在其项目中选择的名称创建存储桶?我不能选择名称namebucket 的原因是因为其他人已经在他们的项目中命名了这样的存储桶吗?

【问题讨论】:

    标签: java google-cloud-platform google-cloud-storage


    【解决方案1】:

    是的,存储桶名称对所有用户都是唯一的。

    查看Documentation for bucket name considerations

    存储桶名称位于单个 Cloud Storage 命名空间中,这意味着每个存储桶名称都必须是唯一的。如果您尝试使用已分配给现有存储桶的名称创建存储桶,Cloud Storage 会以错误消息进行响应。但是,一旦您删除存储桶,您或其他用户可以在创建新存储桶时重复使用其名称

    【讨论】:

    • 所以你的意思是每个谷歌存储用户都使用一个存储命名空间?一旦其他用户使用该名称,我就不能再使用它了吗?好像很奇怪,为什么不绑定到你的谷歌账号呢?
    猜你喜欢
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    • 2021-03-06
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多