Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在谷歌云存储中创建bucket有时会失败_Java_Google Cloud Platform_Google Cloud Storage - Fatal编程技术网

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

Java 在谷歌云存储中创建bucket有时会失败,java,google-cloud-platform,google-cloud-storage,Java,Google Cloud Platform,Google Cloud Storage,我一直在尝试按照本文的指导原则,使用Java在Google云存储中创建存储桶。我有一个方法可以检查bucket是否存在,并返回一个布尔值,如下所示 private boolean checkIfBucketExists(String bucketName) { return storage.get(bucketName, Storage.BucketGetOption.fields()) != null } public Bucket createBucket(String bucket

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

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,如下所示

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 bucket
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."
}

是不是在谷歌云存储中,我无法使用其他用户在其项目中选择的名称创建一个bucket?我之所以不能选择名称
namebucket
,是因为其他人在他们的项目中已经这样命名了一个bucket

是的,bucket名称对于所有用户都是唯一的

检查:

Bucket名称驻留在单个云存储命名空间中,这意味着每个Bucket名称必须是唯一的。如果您尝试使用已分配给现有bucket的名称创建bucket,云存储将以错误消息响应。但是,一旦删除了一个bucket,它的名称可以在创建新bucket时被您或其他用户重用


是的,bucket名称对于所有用户都是唯一的

检查:

Bucket名称驻留在单个云存储命名空间中,这意味着每个Bucket名称必须是唯一的。如果您尝试使用已分配给现有bucket的名称创建bucket,云存储将以错误消息响应。但是,一旦删除了一个bucket,它的名称可以在创建新bucket时被您或其他用户重用


你是说每个google存储用户都使用一个存储名称空间?一旦其他用户使用该名称,我就不能再使用它了?这似乎很奇怪,为什么不将它绑定到您的Google帐户?那么您的意思是每个Google存储用户都使用一个存储名称空间?一旦其他用户使用该名称,我就不能再使用它了?这似乎很奇怪,为什么不把它绑定到你的谷歌账户上呢?