jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
797 stars 135 forks source link

How to delete uploaded file when user navigates to another page before submitting form? #159

Open perkalerk opened 4 years ago

perkalerk commented 4 years ago

Hello,

For my example, let's say a user uploads a file in step 1 of the Wizard, then goes to step 2 and navigates to another page without submitting the form. What method can I use to detect this action so that I can delete the user's uploaded file and not have it junk up the file system?

I've gotten it so that the file is deleted on a reload but not if the user enters a URL into the browser and loads a new page.

ShaheedHaque commented 3 years ago

In general, since the server has no clue that the user has gone away (or indeed might come back), I don't think there is any explicit trigger that one can rely on. What I do is that I ensure all file storage is kept in a well-known tree and run a daily "batch" job that clears the tree of files which have been there more than 2 days.