caktus / django-sticky-uploads

Enhanced file input widget for Django which uploads the file in the background and retains value on form errors.
BSD 3-Clause "New" or "Revised" License
32 stars 9 forks source link

feature request: unique folders in filestorage/temp #14

Closed howew closed 8 years ago

howew commented 9 years ago

Would it be possible to modify the code to store the files in a unique folder within the temp or /tmp directories? This would eliminate the chance of a file residing in the temp folder with the same name, which causes the file to be renamed on the subsequent attempt.

So if you try to upload "myfile.txt" twice, instead of storing it like this: /tmp/myfile.txt (first attempt) /tmp/myfile_3sdf93F.txt (second attempt)

It would store it like this: /tmp/3ksefj3w3/myfile.txt (first attempt) /tmp/sdflk339sf/myfile.txt (second attempt)

For my project, it only makes sense to rename the file if there is a conflict when it is moved to its final destination, not while it is in the temporary directory or other storage folder.

mlavin commented 9 years ago

Yes this would be possible with some modification to the TempFileSystemStorage.

vstoykov commented 9 years ago

I think this with combination of nesting these folders to prevent hundreds and thousands of files in the same directory. Also all random directories need to be placed in one folder in the temp, to be easy for traversing and deleting old files (and probably empty directories).