Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Storage Triggers - Object Deleted event for an overwritten object

I have a Cloud Function set up with a Cloud Storage trigger according to https://cloud.google.com/functions/docs/tutorials/storage#object_delete

The triggering bucket is unversioned so when an object is overwritten the "google.cloud.storage.object.v1.deleted" event will fire and the function is called.

Within the function I need to differentiate between an object being overwritten and an object being permanently deleted, but I cannot see anything in the cloud event payload that differs in these two cases?

0 4 703
4 REPLIES 4

Hi @pan_d,

Welcome to Google Cloud Community!

You can look for the metageneration attribute in the event payload to help distinguish between an object that has been overwritten and one that has been permanently removed in a Cloud Function that has been started by the google.cloud.storage.object.v1.deleted event.

  • The object was overwritten if the metageneration property is present.
  • If the attribute for metageneration is missing, the item was permanently removed.

Hope this helps. Thank you!

Thanks @christianpaula , however the "metageneration" property is present in both cases, and has the same value "1".

I have the same issue, and it appears that the "metageneration" property is present is both cases, file overwritten or deleted. Any assistance to be able to differentiate between the two would be helpful.

As a work-around for now when I get a deleted event I'll do a GCS "exists" check on the file, if the fiile was actually deleted it shouldn't exist in the bucket, if it was overwritten then the file will exist in the bucket and I can ignore the delete event.

Top Solution Authors