porton
porton

Reputation: 5803

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?

Upvotes: 7

Views: 14399

Answers (1)

jterrace
jterrace

Reputation: 67073

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.

Upvotes: 7

Related Questions