Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
.. image:: https://badge.fury.io/py/dj-upload-to.png :target: http://badge.fury.io/py/dj-upload-to :alt:
.. image:: https://travis-ci.org/marazmiki/dj-upload-to.png?branch=master :target: https://travis-ci.org/marazmiki/dj-upload-to :alt: Travis CI build status
.. image:: https://coveralls.io/repos/marazmiki/dj-upload-to/badge.png?branch=master :target: https://coveralls.io/r/marazmiki/dj-upload-to?branch=master :alt: Code coverage percentage
.. image:: https://pypip.in/d/dj-upload-to/badge.png :target: https://pypi.python.org/pypi/dj-upload-to :alt: Latest version on PyPI
.. image:: https://pypip.in/wheel/dj-upload-to/badge.svg :target: https://pypi.python.org/pypi/dj-upload-to/ :alt: Wheel Status
.. image:: https://pypip.in/py_versions/dj-upload-to/badge.png :target: https://pypi.python.org/pypi/dj-upload-to/ :alt: Supported Python versions
Small application that simplifies naming of uploaded files. License is MIT.
You can get dj-upload-to
release version from pypi with pip
:
.. code:: bash
$ pip install dj-upload-to
or development one from github:
.. code:: bash
$ pip install -e git+https://github.com/marazmiki/dj-upload-to#egg=dj-upload-url
You're not need include it into your INSTALLED_APPS
Assumes you have model:
.. code:: python
from django.db import models
from dj_upload_to import UploadTo
upload_to = UploadTo()
class Model(models.Model):
file = models.ImageField(upload_to=upload_to)
As you see, UploadTo
generates callable object (with __call__
methodfor passing into upload_to
attribute of FileField (see django upload_to docs <https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to>
_ for details)
When you save model with image originally named myphoto.JPG
, file
will be saved with name such as:
.. code:: bash
model/ab/cd/abcdabcd-0123-4567-8901-234567890ab.jpg
where:
model
is prefix automatically generated from model class. You can override itab
is the first 2 char segment of filenamecd
is the second 2 char segment of filenameabcdabcd-0123-4567-8901-234567890ab
autogenerated with uuid
filename.jpg
is a lower cased extension taken from original fileYou can customize behavior of UploadTo
with options in constructor:
prefix
: prefix of filename. Default is dj_upload_to.not_provided
. If None
, prefix will be missed. If not explicitly set, will be generated automatically based on model class namenum_seg
: number of parts of segmentation. Default is 2
seg_size
: length of segment in chars. Default is 2
save_name
: use original name without autogeneration. Default is False
There are some examples:
.. code:: python
>>> model_instance = Model()
>>> # Disable prefix
>>> UploadTo(prefix=None)(model_instance, 'file.jpg')
u'c0/17/c01745b4-e70b-4dd8-a5f7-76fec32fcb83.jpg'
>>> # Explicitly given prefix
>>> UploadTo(prefix='my_files')(model_instance, 'file.jpg')
u'my_files/d9/a4/d9a4ef25-11b0-41bb-a543-baaac6553024.jpg'
>>> # Four segment and automatically generated prefix
>>> UploadTo(num_seg=4)(model_instance, 'file.jpg')
u'model/36/52/99/f6/365299f6-8dc5-4ca2-848d-965f002a9b72.jpg'
>>> # Segment length is 4 chars
>>> UploadTo(seg_size=4)(model_instance, 'file.jpg')
u'model/3142/f2ef/3142f2ef-2680-4a99-82fc-3c8d9d3179dc.jpg'
>>> # Save original filename
>>> UploadTo(save_name=True)(model_instance, 'file.jpg')
u'model/file.jpg'
>>> # Save original filename without prefix
>>> UploadTo(save_name=True, prefix=None)(model_instance, 'file.jpg')
u'file.jpg'
Ideas, bugfixes, pull requests are welcome on GitHub <https://github.com/marazmiki/dj-upload-to>
_
Initial release
FAQs
Small application that simplifies naming of uploaded files
We found that dj-upload-to demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.