Skip to main content
https://circleci.com/gh/naeem91/django-upload-validator/tree/master.svg?style=svg

Django Upload Validator is a simple utility for validating file types and extensions using python-magic library.

Installation

Install the current PyPI release:

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

  1. Install testing requirements pip install -r tests/requirements.txt

  2. Run python runtests.py inside the root directory of package

Metadata

Release files for django-upload-validator 1.1.6

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

Source distribution (sdist)

Source distribution for django-upload-validator 1.1.6
File Size Uploaded
django-upload-validator-1.1.6.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-upload-validator 1.1.6
File Interpreter ABI Platform
django_upload_validator-1.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 31.8 kB

Release files / django-upload-validator-1.1.6.tar.gz

Download URL django-upload-validator-1.1.6.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dbf93740fb42f8c9310b936838bbf99f873339c2f860de1c7c0d7a27464f7c8a
BLAKE2b-256 checksum
How to use checksums
ed99f4476cb7350ea6fef1f037a6346be635754ff4e870b323a562a5151fe2a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.1

Release files / django_upload_validator-1.1.6-py3-none-any.whl

Download URL django_upload_validator-1.1.6-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4c1a2d2138b319288a20069c5dbdbbdb1257a447ec2f0b4e6cf9e8d6fd3d1bc
BLAKE2b-256 checksum
How to use checksums
1120d6f75e016f06a5c73bd2fe2ea7a3714093538a57131ea15f55c0fb65b407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.1

Release history Release notifications | RSS feed

This release

1.1.6 This release

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.2

2 release files

1.0.2

1 release file

1.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