在谷歌云存储中创建存储桶有时会失败

我一直在尝试使用Java按照此链接中的指南在Google云存储中创建存储桶。我有一个方法,可以检查存储桶是否存在并返回一个布尔值,如下所示


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());

  }

当我创建一个桶时,它有时表现得有点奇怪。例如,我可以创建一个命名的 ,但不能,即使我的项目中没有一个存在。它给了我这个错误bucketname-bucketnamebucketnamebucket


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云存储中,我无法使用其他用户在其项目中选择的名称创建存储桶吗?我无法选择名称的原因是其他人已经在他们的项目中命名了这样的存储桶?namebucket


holdtom
浏览 196回答 1
1回答

尚方宝剑之说

是的,存储桶名称对于所有用户都是唯一的。请查看文档以了解存储桶名称注意事项:存储桶名称驻留在单个云存储命名空间中,这意味着每个存储桶名称都必须是唯一的。如果您尝试使用已分配给现有存储桶的名称创建存储桶,Cloud Storage 将回复一条错误消息。但是,删除存储桶后,您或其他用户在创建新存储桶时可以重复使用其名称。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java