簡體   English   中英

有時無法在Google Cloud Storage中創建存儲桶

[英]Creating bucket in Google Cloud Storage fails sometimes

我一直在嘗試使用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());
  }

當我創建存儲桶時,有時會有些奇怪。 例如,我能夠創建一個bucket命名name-bucket ,但不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原因是因為其他人已經在他們的項目中像這樣命名了一個桶?

是的,存儲桶名稱對於所有用戶都是唯一的。

查看文檔以了解存儲桶名稱注意事項

存儲桶名稱位於單個Cloud Storage名稱空間中 ,這意味着每個存儲桶名稱都必須是唯一的。 如果您嘗試使用已分配給現有存儲桶的名稱來創建存儲桶,則Cloud Storage會顯示一條錯誤消息。 但是,刪除存儲桶后, 您或其他用戶在創建新存儲桶時可以重用其名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM