Skip to main content

A Django storage backend that names files by hash value.

By default, django.core.files.storage.FileSystemStorage deals with conflicting filenames by appending an underscore to the file. For instance, if you try to create hello.txt when it already exists, it will rename it as hello_.txt.

django-hashedfilenamestorage creates hashed filenames, so if you try to create hello.txt with the content Hello world!, it will save it as d3486ae9136e7856bc42212385ea797094475802.txt. Directory names and extensions are preserved, only the root filename is changed. This reduces the number of duplicates stored in the underlying backend, and implies that these files can be served from a static cache that never expires.

Installing

The easiest way to install django-hashedfilenamestorage is to use pip:

pip install django-hashedfilenamestorage

Quick Start

In your Django settings file:

  • Set DEFAULT_FILE_STORAGE to 'django_hashedfilenamestorage.storage.HashedFilenameFileSystemStorage'

This gives you hashed filenames, backed on Django’s FileSystemStorage storage class.

HashedFilenameMetaStorage

You can define a new underlying storage class by using HashedFilenameMetaStorage to wrap it:

from django.core.files.storage import get_storage_class

from django_hashedfilenamestorage.storage import HashedFilenameMetaStorage

HashedFilenameMyStorage = HashedFilenameMetaStorage(
    storage_class=get_storage_class('myapp.storage.MyStorage'),
)

Hashing algorithm

HashedFilenameMetaStorage is meant to generate duplicate filenames for files with identical contents. To do this, it reads the contents of the file and generates a SHA-1 hash of them.

Filenames have their extensions preserved, so it is possible to have duplicate contents on the filesystem, but it is important to help serve files with their proper content types.

Metadata

Release files for livingbio-django-hashedfilenamestorage 2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for livingbio-django-hashedfilenamestorage 2.1
File Size Uploaded
livingbio-django-hashedfilenamestorage-2.1.tar.gz 4.1 kB Details

Release files / livingbio-django-hashedfilenamestorage-2.1.tar.gz

Download URL livingbio-django-hashedfilenamestorage-2.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
48ad7b59035878009d0c9d81deff7df46478c38f36fa26e93ea8f252094b64e4
BLAKE2b-256 checksum
How to use checksums
143c4309099976f7b80c9dab351d2bc3496974ae939e71038c9cad87229ea31d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.1 This release

1 release file

2.0

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page