[Similar question posted in Software Engineering but reposted here as was considered a bit off-topic].
My Flask astronomy app includes functionality which implements a multi-step wizard. Step 1 permits the user to upload an astronomical image file (typically 32mb). Step 2 permits the user to specify parameters for an Astropy module to identify potential stars within the image and match them to an online stellar database. Step 3 permits the user to define a series of filters to define the stars of interest and the final Step 4 saves the filtered star data and deletes the uploaded image.
The image uploaded in Step 1 is currently saved in the Flask Instance Folder (in a sub-folder specific to the Current User) and is deleted in Step 4.
However there will be many situations where the file doesn’t get deleted because the wizard never reaches Step 4 (user navigates to another page without cancelling the wizard, they lose their Internet connection, their PC crashes, etc).
So I need a fool-proof way of deleting orphaned uploaded images. I’ve considered a scheduled task that runs periodically and deletes files > n minutes old, but that seems crude.
Is there a better way?