Skip to main content

A simple Django file type validator using python-magic

Project description

https://circleci.com/gh/mckinseyacademy/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']
    )]
)

Running Tests

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

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

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-upload-validator-1.1.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

django_upload_validator-1.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file django-upload-validator-1.1.2.tar.gz.

File metadata

  • Download URL: django-upload-validator-1.1.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.1

File hashes

Hashes for django-upload-validator-1.1.2.tar.gz
Algorithm Hash digest
SHA256 296a80f5dbe19b559d535b8121490a08c016df597c7de085162a3569db151d41
MD5 73ec7e74abff8c5e05d15a2074dcb7c3
BLAKE2b-256 d7c33457555c92c89241e44b7d382c9cb4a27096984fb618cb79154c7c655ad5

See more details on using hashes here.

File details

Details for the file django_upload_validator-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: django_upload_validator-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.1

File hashes

Hashes for django_upload_validator-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2502b6fcd096dd1d3ec5fa37216afc1876e919dc5c203839827479b37015e84a
MD5 365f208a0c7aee0d50e30cf53c23c6f9
BLAKE2b-256 384be2be5c73290dca509155671241f585ff518e139dcdb97ac2895bd633bbf3

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