GeezerVison is showing github.com — Storage: Can't specify project when creating a bucket · Issue #2643 · googleapis/google-cloud-java
Storage: Can't specify project when creating a bucket #2643
Labels
api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design. Description
The client library allows users to create GCS buckets, and it will create them using the project specified when setting up the client. However, there is no way to overrule this and specify a project number at the time of bucket creation.
Activity
yihanzhen commented on Dec 11, 2017
Hi @BrandonY -
Thanks for letting us know the issue. Based on my understanding, the best way to create a bucket for a different project is to create a different storage client. Here is a short sample code for your reference:
Storage storage1 = StorageOptions.newBuilder().setProjectId("project1").getService();
Storage storage2 = StorageOptions.newBuilder().setProjectId("project2").getService();
Bucket bucket1 = storage1.create(BucketInfo.of("bucket-1-name"));
Bucket bucket2 = storage2.create(BucketInfo.of("bucket-2-name"));
The code is repeating but this should be the best practice for now. The reason we are not able to give a public method to specify a projectId when creating a bucket is that the projectId is in deep integration with the client objects (storage1 and storage2 in this case) for all the APIs, and we are not able decouple the two for the moment. If creating a new storage client gives you a lot of problems, please let us know and we will add your request to our long-term plan.
BrandonY commented on Dec 12, 2017
That makes sense. Still, other products seem to offer this. For example, with the pubsub client, I can do this:
TopicName name = TopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
Either way, it shouldn't be a big deal to create a new client when choosing a different project.
added 2 commits that reference this issue
on Mar 24, 2026This issue will close once commit 806a52e is merged into the 'main' branch.806a52e This issue will close once commit c56daec is merged into the 'main' branch.c56daec
Metadata
Metadata
api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design. Development
No branches or pull requestsIssue actions