Repository navigation
Check if Bucket.exists()? #1133
Description
Activity
Hi @raintears,
Bucketis a class that contains all information of a bucket, in contrast withBucketInfo, theBucketclass also exposes methods toupdateanddeletethe bucket.Bucketobjects cannot be created directly but are returned byStoragemethods likecreateandget.To check for the existence of a bucket if you do not have an instance of
Bucketyou can do the following:return storage.get("bucketname", Storage.BucketGetOption.fields()) != null;
storage.getwill return aBucketobject ornullif not found.Storage.BucketGetOption.fields()tells the service to return only the bucket name (we don't need to transfer all bucket's fields to check for existence).Reacted by raintears, Gerry Surya, Kartik, Kevin Kibue Kariuki, Jay Sardhara, Carlos Pupo Ortiz, Dan McCabe, mazegen and Shubham JainThanks @mziccard
This explanation is more straightforward!
@mziccard which package did you get your Storage class from?
I'm using com.google.api.services.storage.Storage and BucketGetOptions.fields() is not getting resolved.Reacted by Pascal, Keith and Mohamed Benothmane- added a commit that references this issue
on Dec 22, 2025 - added a commit that references this issue
on Jan 6, 2026 - added a commit that references this issue
on Mar 30, 2026 - added a commit that references this issue
on Apr 1, 2026 - added a commit that references this issue
on Jul 13, 2026
Hi,
I still can't understand how can I use bucket.exists from the documentation. I don't even know how to instantiate a new bucket. This is what I did.
Bucket bucket = new Bucket("bucketname");
return bucket.exists();
Apparently I can't instantiate a new bucket like this, so how then can I use bucket.exists()?