0
votes

I am making an android app where the user can upload images under some category. It will be saved on firestore with category collection with image description and path of the image of firebase storage. I want to delete the photo which are 7 days old automatically using cloud function. I don't want to involve the client device to trigger the function.

1

1 Answers

1
votes

You will end up a writing a lot of code for this. A full discussion is outside the scope of a Stack Overflow answer. The general procedure goes like this:

  • Write a Storage trigger that fires when the user uploads the file.
  • In that trigger, use Cloud Tasks to schedule an invocation of an HTTPS function using its URL, delayed after 7 days. The task must be configured to deliver a payload to the function that tells it which file to delete.
  • In the HTTPS trigger, receive the payload, and delete the file from Storage.

It will be similar to an existing detailed pattern for giving a Firestore document a TTL, except you are using a Storage file instead of a Firestore document.