Tamporarily Saving And Sanitizing Image Objects In Django
Solution 1:
The main problem of using sessions is that they're not meant to handle a lot amount of data, and they could potentially loss information due to encoding, the RAM filling up, the framework's process of garbage collection, and such. That really dependes on how you store sessions objects, if you already solved this problem, go to step two.
Step One: You may want to make a separate model to store the image temporarily, storing the date and image file reference (through an ImageField), you can tell this model to upload the file to a temporary location on the Media directory using the upload_to
parameter of the field.
Step Two: Set up a management command that filters the orphaned models from a certain date (images older than 10 minutes or so), and then deletes them along with the images (this is very important, as deleting the database record does not delete the file). The management command should be able to run without user intervention. Read more about management commands here.
Step Three: Set up your machine's Crontab or whatever you use to schedule processes, to run the management command in a daily or hourly basis depending on your needs.
Post a Comment for "Tamporarily Saving And Sanitizing Image Objects In Django"