Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Storage: how to check if an object exists?

What is the best JSON API method to check if an object with the given name exists in a Google storage bucket?

like image 468
porton Avatar asked Jan 16 '17 21:01

porton


People also ask

Does Google Drive use object storage?

Google Cloud Storage is the object storage service offered by Google Cloud.

What is Google's object storage called?

Cloud Storage is a service for storing your objects in Google Cloud. An object is an immutable piece of data consisting of a file of any format. You store objects in containers called buckets.


1 Answers

You can use storage.objects.get and check for a 404 response. Alternatively, if you want to create an object only if doesn't already exist, you can set the ifGenerationMatch parameter to 0. If the object already exists, a precondition failure will be returned.

like image 173
jterrace Avatar answered Oct 18 '22 20:10

jterrace