Omnimaga
General Discussion => Technology and Development => Web Programming and Design => Topic started by: Michael_Lee on September 16, 2011, 07:43:41 pm
-
I'm taking user input (in a text box or whatever), and trying to make a file the user can then download. What is the best way of managing the newly created files?
Should I assign them a unique name, based on a hash or something? Or is there a way to preserve filenames without risking accidental name collision?
I really don't want a bunch of files to be created and slowly take up a huge amount of memory -- what's the best way of managing and purging temporary downloadable files?
(I'm trying to make something based of off Javascript and Python).
-
Maybe this? http://docs.python.org/library/tempfile.html (http://docs.python.org/library/tempfile.html)
Edit: On the note of preserving filename, perhaps you could create a temporary directory with tempfile.mkdtemp() and put your file in that.
-
You might want to make a script that output the file you're generating without putting it in a temp file on disk (with print or something instead of the function you use to write to a file, I don't really know Python). You can then specify the MIME type and the filename with appropriate HTTP headers.