Django form wizard: Delete temporary files stored by intermediate steps
Asked Answered
G

2

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?

Galloromance answered 26/7, 2013 at 13:46 Comment(0)
A
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.

Anzus answered 27/7, 2013 at 9:37 Comment(1)
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.Galloromance
C
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.

Corallite answered 27/8, 2014 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.