Skip to main content

Generate short UUIDs and use them as paths for uploaded media files in Django.

Project description

django-file-upload-to

django-file-upload-to generates short UUIDs to use as paths for uploaded media files in Django.

Features

  • Generate short (22 character), URL-safe base64-encoded UUIDs.
  • Upload media files to short UUID filenames.

Installation

  1. Checkout the latest django-file-upload-to release and copy or symlink the uuid_upload_path directory into your PYTHONPATH. If using pip, run pip install django-file-upload-to.

Generating short UUIDs

Generate a short, URL-safe UUID as follows:

::

from uuid_upload_path import uuid

uuid()  // -> "hCdLEjlQQJW25-sXB3T_Gw"

Generating upload paths

To upload media files to short UUID filenames, just set upload_to to uuid_upload_path.upload_to.

::

from uuid_upload_path import upload_to

class YourModel(models.Model):

    file = models.FileField(
        upload_to = upload_to,
    )

Why use UUIDs as upload paths?

Django tries to ensure that all your uploaded files are given unique names on the filesystem. It does this by checking if a file with the same name exists before saving a new one, and adding a suffix if the new file would otherwise conflict with the existing one.

If you're saving files to disk using the built-in django.core.files.storage.FileSystemStorage, this isn't much of a problem. However, if you're using a cloud file storage, such as storages.backends.s3boto.S3BotoStorage, this uniqueness check can have a noticeable effect on the performance of file uploads. Worse, the default configuration of S3BotoStorage is to overwrite existing files with the same name when uploading a new file!

By generating a unique filename for each uploaded file, django-file-upload-to removes the need for a costly uniqueness check, and avoids accidentally overwriting existing files on remote cloud storages.

Support and announcements

Downloads and bug tracking can be found at the main project website <https://github.com/panttojo/django-file-upload-to>_.

More information

The django-uuid-upload-path project was developed by Dave Hall and forked for make a little customizations. You can get the code from the django-uuid-upload-path project site <https://github.com/etianen/django-uuid-upload-path>_.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-file-upload-to-2.0.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_file_upload_to-2.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django-file-upload-to-2.0.0.tar.gz.

File metadata

  • Download URL: django-file-upload-to-2.0.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for django-file-upload-to-2.0.0.tar.gz
Algorithm Hash digest
SHA256 69f8bb604a62c781a684e5ab7b54ac975b911feec68b05c9f81f7a332c3aae95
MD5 412dc9ac7b6aecd4cbc740b70c0a778d
BLAKE2b-256 19915238f0dc93c097413ad99ecf19aba233d3e7cb22227c434039e590ccee92

See more details on using hashes here.

File details

Details for the file django_file_upload_to-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_file_upload_to-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for django_file_upload_to-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7b3b62105829e18666a69d21eb36f92f7850b1dad851f21bd4a05a1e9a09d9
MD5 a22ade4975136c7cf698aa1892f76f15
BLAKE2b-256 55f78c2403b43382a007a56114781a26f1d767bf567848a35c7226db6212ae2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page