I am curious to see if there is an established best practice for removing images no longer used from Cloudinary if they've been uploaded with the Widget and the only reference available is the image display URL provided by the widget.
- Client can:
- leave page without saving it to his account (orphaned image in cloudinary)
- replace an existing image (previous image saved is no longer in use/orphaned)
- save image to his profile. In this case, we save the image's display URL in the backend
- If user has saved the image, the image's display URL overwrites whatever is in the field representing that image in the database. There are multiple tables with multiple fields that store these URLS, so no one singular "images" resource to retrieve from.
If this scenario is common and has a well established process to remove the orphaned images or images no longer in use, please let me know.
Otherwise, our thoughts are:
- Let user upload image through widget
- On successful upload, send a message to our servers that an image with given URL has been uploaded to cloudinary (as well as in which table/field/resource it is being stored for)
- Enqueue this message into a background job queue with url, resource identifier
- Wait some amount of time (a week or so)
- check our database at the identified resource location (table/field) to see if the upload URL matches what is in the queue.
- If so, leave it alone; if not, send a delete request to cloudinary
- remove our queue message
Please sign in to leave a comment.