java如何在google cloud storage builder中设置项目ID?
我正试图将图像上传到Google Cloud storage
,但在创建StorageOptions
时,我遇到了project must be specified.
异常
我遵循官方文档,在执行以下步骤后选择使用Json
凭证:
- 创建一个新的
Service Account Key
- 在
Role
中,我选择了Owner
(稍后更改) 下载
Json
键,并使用以下示例与之连接public static void main(String[] args) throws IOException { Storage storage = StorageOptions.newBuilder() .setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream("/Users/test/sample/app/project-936c0c6ef960.json"))) .build() .getService(); String bucketName = "Sample"; Bucket bucket = storage.create(BucketInfo.of(bucketName)); System.out.printf("Bucket %s created.%n", bucket.getName()); }
我做错了什么
# 1 楼答案
人力资源经理,看来你是对的。在使用Java客户机创建bucket时,似乎没有一种设置项目的方法。我提交了一个错误:https://github.com/GoogleCloudPlatform/google-cloud-java/issues/2643
在设置StorageOptions时,您可能可以通过指定项目来解决这个问题: