Project description
Django Upload Validator is a simple utility for validating file types and extensions using python-magic library.
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 pip install -r tests/requirements.txt
Run python runtests.py
inside the root directory of package
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages .
Source Distribution
Built Distribution
File details
Details for the file django-upload-validator-1.1.6.tar.gz
.
File metadata
Download URL:
django-upload-validator-1.1.6.tar.gz
Upload date: Feb 12, 2022
Size: 16.0 kB
Tags: Source
Uploaded using 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
File hashes
Hashes for django-upload-validator-1.1.6.tar.gz
Algorithm
Hash digest
SHA256
dbf93740fb42f8c9310b936838bbf99f873339c2f860de1c7c0d7a27464f7c8a
Copy
MD5
80af737ece530ebf8c382cbca66f778c
Copy
BLAKE2b-256
ed99f4476cb7350ea6fef1f037a6346be635754ff4e870b323a562a5151fe2a9
Copy
See more details on using hashes here.
File details
Details for the file django_upload_validator-1.1.6-py3-none-any.whl
.
File metadata
Download URL:
django_upload_validator-1.1.6-py3-none-any.whl
Upload date: Feb 12, 2022
Size: 15.8 kB
Tags: Python 3
Uploaded using 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
File hashes
Hashes for django_upload_validator-1.1.6-py3-none-any.whl
Algorithm
Hash digest
SHA256
b4c1a2d2138b319288a20069c5dbdbbdb1257a447ec2f0b4e6cf9e8d6fd3d1bc
Copy
MD5
4941f24767bec35234233fbab91ca223
Copy
BLAKE2b-256
1120d6f75e016f06a5c73bd2fe2ea7a3714093538a57131ea15f55c0fb65b407
Copy
See more details on using hashes here.