django-icekit icon indicating copy to clipboard operation
django-icekit copied to clipboard

Use deterministic unique file names for file and image libraries

Open mrmachine opened this issue 8 years ago • 1 comments

Our default storage class for file and image libraries should automatically determine the file name name by hashing the file content. This will:

  1. De-duplicate uploads
  2. Allow us to serve all files (not only static media) with far-future expiry (100 years)

We should store the original file name in a field on the model, so we can set it on response headers so that direct downloads will be saved locally with the original filename. This means we can also have multiple distinct files for download with the same file name metadata.

The admin change list should show and search the original filename.

This behaviour is already implemented in an ixc-whitenoise mixin, and commented out in ICEkit's default storage class:

  • https://github.com/ixc/ixc-whitenoise/blob/bb63ba1d578925eed052e5f256b78151692a7e23/ixc_whitenoise/storage.py#L51-L80
  • https://github.com/ic-labs/django-icekit/blob/d27b6394e6f81a4e12187dc050752deb1532dc43/icekit/utils/storage.py#L58

We just need to:

  • [ ] make it the default
  • [ ] add the original file name field to file and image library models
  • [ ] display and search the original file name in admin change list
  • [ ] add a download view that adds the original file name
  • [ ] update existing projects

mrmachine avatar Mar 23 '17 03:03 mrmachine

This approach would also help #161 : Two file uploads with the same filename will overwrite each other

jmurty avatar May 08 '17 04:05 jmurty