我想在桶中创建一个blob。 我已经在谷歌云中创建了存储桶,创建了服务帐户,并允许所有者访问该存储桶访问相同的服务帐户。稍后创建的服务帐户密钥 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."
}
| Grails版本:3.2.10 | Groovy版本:2.4.10 | JVM版本:1.8.0_131
谷歌云的数据存储区:1.2.1
谷歌-AUTH-库的oauth2-HTTP:0.7.1
谷歌云的存储:1.2.2
答案 0 :(得分:1)
关于json文件对应的服务帐户 - 我打赌:
A)您尝试访问的存储桶属于与您将该帐户设置为存储管理员的项目不同的项目
或B)您正在设置与json文件对应的
不同的服务帐户的权限