简体   繁体   中英

Cloud Functions: Delete file on Cloud Storage when Firestore document is deleted

I have a cloud function which listens for onDelete events. When a document is deleted, I also want an associated file on the storage to be deleted. Currently I have only the download-url (https link) stored as a field in the document.

How can I select the file within the function? Is this possible or should I store the storage location (path) of the file inside the document and use that to do:

storage.bucket(<my-bucket>).file(<path>).delete()

The Cloud Storage SDK doesn't have a way to convert an HTTPS download URL into a file path in your storage bucket. If you need to know the path to a file in Cloud Storage, you should store that path as another field in your database. This will make it easy to reach back into your storage bucket to delete the file when needed.

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