
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
django-upload-validator
Advanced tools
Django Upload Validator
.. image:: https://circleci.com/gh/naeem91/django-upload-validator/tree/master.svg?style=svg :target: https://circleci.com/gh/naeem91/django-upload-validator/tree/master
Django Upload Validator is a simple utility for validating file types and extensions using python-magic
library.
Installation ############
Install the current PyPI release <https://pypi.python.org/pypi/django-upload-validator>
__:
.. code:: bash
pip install django-upload-validator
Usage
General usage ::
from upload_validator import FileTypeValidator
validator = FileTypeValidator(
allowed_types=['application/msword'],
allowed_extensions=['.doc', '.docx']
)
file_resource = open('sample.doc')
# ValidationError will be raised in case of invalid type or extension
validator(file_resource)
Usage as a FileField validator in Django forms ::
from upload_validator import FileTypeValidator
profile_image = forms.FileField(
label='', help_text="Formats accepted: JPEG nd PNG", required=False,
validators=[FileTypeValidator(
allowed_types=[ 'image/jpeg','image/png']
)]
)
Wildcard character specification is also supported. e.g; for accepting only images: ::
profile_image = forms.FileField(
label='', help_text="Only image formats are accepted.", required=False,
validators=[FileTypeValidator(
allowed_types=[ 'image/*']
)]
)
Running Tests
#############
#. Install testing requirements :code:pip install -r tests/requirements.txt
#. Run :code:python runtests.py
inside the root directory of package
FAQs
A simple Django file type validator using python-magic
We found that django-upload-validator 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.