简体   繁体   中英

Stop object finalize event when google cloud storage object is renamed

hint: this doesn't need a code sample

I'am working with google cloud storage and cloud functions, the case demands triggering the function when an object is uploaded via ( Object finalized ) event , the chain goes as listening to the event from cloud functions, generate a random string, call some api that commits to a db, and rename the same object with the random string attached, when this happens -renaming the object via bucket.rename_blob -, google cloud storage triggers the finalize event again thus the same function is called again in a randomly-ended loop (noticed uploading an object generates about 23 names in the db), anyway to stop propagating the event when the object is renamed?

As we can read in the doc for bucket.rename_blob , this method "copies blob to the same bucket with a new name, then deletes the blob". This is why your Cloud Function is triggered again and again, since each time you rename an Object a new Object is created, which triggers the finalized event.

The only way I can see is to store in a DB the new Object name and, in the Cloud Function, check if this name is present in the DB: If it is present you don't execute the Cloud Function business logic since this Object name is the one of a renamed object.

You can very well use Cloud Firestore as the DB to store those names, or any other DB of your choice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM