6

I am using django(1.4) formwizard for my application. In step 1 I am uploading 2 files. These files are used in second step. Everything is working fine but this ---> "When I complete all steps OR I stop after step 1 I still have temporary files stored in MEDIA directory"

How can I ensure that these files are deleted in any of the cases?

Aryaveer
  • 943
  • 1
  • 12
  • 27

2 Answers2

2

Django says on the documentation that you have to manage these files yourself, so:

You can set the uploading path to /tmp (if you are using Linux), so that they are automatically deleted.

Another approach is that you can write a script to run periodically and delete them.

Nikign
  • 379
  • 3
  • 9
  • you are right but consider this --> a user upload files in step 1 and then hit prev button and upload some different file. In this case we have older and newer files. Another case if I run some script periodically I might delete some files which a user just uploaded in step 1 and he is about to submit step 2. – Aryaveer Jul 27 '13 at 10:08
0

You need to make 2 steps solution.

First step is to set on the wizard view, the file_storage variable, with params to identify the wizard execution, in order to avoid errors on prev next steps you told on the last comment.

And then in the done() function on the wizard, delete all the folder contents(remember to use some unique schema for each wizard in the execution), so you can delete all the files on submit, before end the wizard.

NeoMorfeo
  • 300
  • 1
  • 3
  • 14