代码之家  ›  专栏  ›  技术社区  ›  Etibar - a tea bar

从Grails应用程序访问Google云存储

  •  1
  • Etibar - a tea bar  · 技术社区  · 8 年前

    从grails应用程序中,我想在bucket中创建一个blob。 我已经在谷歌云中创建了bucket,创建了 并允许所有者访问相同的存储桶 服务帐户 project-id-c4b144.json 它拥有所有的证书。

    StorageOptions storageOptions = StorageOptions.newBuilder()
                                .setCredentials(ServiceAccountCredentials
                                .fromStream(new FileInputStream("/home/etibar/Downloads/project-id-c4b144.json"))) // setting credentials
                                .setProjectId("project-id") //setting project id, in reality it is different
                                .build()
                        Storage storage=storageOptions.getService()
                        BlobId blobId = BlobId.of("dispatching-photos", "blob_name")
                        BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build()
                        Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(StandardCharsets.UTF_8))
    

    当我运行这段代码时,我收到一条json错误消息。

    Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
    {
      "code" : 403,
      "errors" : [ {
        "domain" : "global",
        "message" : "Caller does not have storage.objects.create access to bucket dispatching-photos.",
        "reason" : "forbidden"
      } ],
      "message" : "Caller does not have storage.objects.create access to bucket dispatching-photos."
    }
    

    |Groovy版本:2.4.10

    谷歌云数据存储:1.2.1

    1 回复  |  直到 6 年前
        1
  •  1
  •   mhouglum    8 年前

    关于json文件对应的服务帐户——我打赌:

    A) 您试图访问的存储桶属于不同的项目,而不是您将该帐户设置为存储管理员的项目