Backend Workflow : Delete image when not stored in database

OK, I tried this for 4 hours and am stuck. I need some bubbly help:

  • I like to run a backend workflow to cleanup my data. This shall run every night.
  • The process shall compare two things: I have a data table that registers all uploaded images by the users (asimple list with only the image path). Also, I have a data table with application data by the users, here I also record the 3 images they shall upload.
  • In case a user uploded many images but did not submit his application, I have now these images as “trash” in my system. I can find them by comparing if the images in the “userUpload” table is also in the “application” table - if not, it is an unused image and can be deleted.

I have real troubles setting this logic up. I came to this setup finally, but it is far from optimized:

  • I run 2 workflows. The first one is running another API workflow for a list of things (all userUpload images) and hands over this userUpload image to the second workflow. The second workflow is taking this as parameter and searches in all data by the application table for this image path. If it does not find it, it deletes the file.

However: This creates a really heavy MU workload, as I do a full search request on every image. I wonder if there is any best practise or better way to clean up images in a smarter and lighter way?

On userUpload table, add a field Submitted? (yes/no). Set the images to yes when an application is submitted. Now you can just search for the images that are not submitted and delete them.

Why not stop them on upload, if it’s the 4th image - block it or ask them to replace an existing image. Then users can only ever upload 3 images. Then you’re not cleaning up at the end, you’re setting better practice from the start.

Removing files is a PITA - as you’re discovering. So it may be worth the investment now to housekeep from the start, and not later on.

Use the Better Uploader plugin instead. It’s free and allows the images to be stored in clientside memory instead of uploading to Bubble before you actually need to save them.