Skip to main content

Chunking Django file handlers for S3 and ClamAV service uploads

Project description

This library provides two Django file upload handlers.

The first of these, s3 provides chunk uploading to an AWS S3 bucket and is heavily based on

The second provides chunk uploading to a ClamAV rest endpoint provided by - although it could be used with other compatibile projects.

If used together, the results of the anti virus check are written to the object uploaded to S3.


pip install django-chunk-upload-handlers


Using in a Django logging configuration:


)  # Order is important


This project is a Django app and depends on the Django package.

The s3 file handler depends on boto3 and django-storages

settings.DEFAULT_FILE_STORAGE must be set to "storages.backends.s3boto3.S3Boto3Storage" or a class that derives from it.




Provide either for the AWS access key required. CHUNK_UPLOADER_AWS_ACCESS_KEY_ID is preferred if both are set.


Provide either for the AWS access secret key required. CHUNK_UPLOADER_AWS_SECRET_ACCESS_KEY is preferred if both are set.


The S3 bucket to use for uploads. CHUNK_UPLOADER_AWS_STORAGE_BUCKET_NAME is preferred if both are set.


The AWS region to use. CHUNK_UPLOADER_AWS_REGION is preferred if both are set.


The directory path to use as root for uploads. CHUNK_UPLOADER_S3_ROOT_DIRECTORY is preferred if both are set.

CHUNK_UPLOADER_RAISE_EXCEPTION_ON_VIRUS_FOUND Defines whether or not to throw an exception if a virus is found. Defaults to False.


CLAM_AV_USERNAME The ClamAV service username.

CLAM_AV_PASSWORD The ClamAV service password.

CLAM_AV_DOMAIN The domain to use for the ClamAV service. Note, this is domain only so rather than

CLAM_PATH The path to the ClamAV service (used with the domain defined in the setting above). Defaults to /v2/scan-chunked

CLAM_AV_IGNORE_EXTENSIONS A list of file extensions to not process with ClamAV. Defaults to an empty list.

CLAM_USE_HTTP Use http rather than https. Should not be used in production environments. Defaults to False.

Usage with file fields

The package provides a validator for use with form and model fields.

The CHUNK_UPLOADER_RAISE_EXCEPTION_ON_VIRUS_FOUND should not be set to True when using this validator.

from django import forms
from django_chunk_upload_handlers.clam_av import validate_virus_check_result

class ExampleForm(forms.Form):
    example_form_field = forms.FileField(
        validators=[validate_virus_check_result, ]

from django.db import models

class ExampleModel(models.Model):
    example_model_field = models.FileField(
        validators=[validate_virus_check_result, ],

The validation message will display ‘A virus was found’ if a virus is detected. This message is a translation string.


$ pip install -r requirements.txt
$ tox

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_chunk_upload_handlers-0.0.13.tar.gz (9.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page