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 https://pypi.org/project/s3chunkuploader/
The second provides chunk uploading to a ClamAV rest endpoint provided by - https://github.com/uktrade/dit-clamav-rest/ although it could be used with other compatible projects.
If used together, the results of the anti virus check are written to the object uploaded to S3.
Installation
pip install django-chunk-upload-handlers
Usage
Using in a Django logging configuration:
INSTALLED_APPS = [
...
"django_chunk_upload_handlers",
]
FILE_UPLOAD_HANDLERS = (
"django_chunk_upload_handlers.clam_av.ClamAVFileUploadHandler",
"django_chunk_upload_handlers.s3.S3FileUploadHandler",
) # Order is important
Dependencies
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.
Settings
S3
AWS_ACCESS_KEY_ID
CHUNK_UPLOADER_AWS_ACCESS_KEY_ID
Provide either for the AWS access key optional. CHUNK_UPLOADER_AWS_ACCESS_KEY_ID is preferred if both are set.
AWS_SECRET_ACCESS_KEY
CHUNK_UPLOADER_AWS_SECRET_ACCESS_KEY
Provide either for the AWS access secret key optional. CHUNK_UPLOADER_AWS_SECRET_ACCESS_KEY is preferred if both are set.
AWS_STORAGE_BUCKET_NAME
CHUNK_UPLOADER_AWS_STORAGE_BUCKET_NAME
The S3 bucket to use for uploads. CHUNK_UPLOADER_AWS_STORAGE_BUCKET_NAME is preferred if both are set.
AWS_REGION
CHUNK_UPLOADER_AWS_REGION
The AWS region to use. CHUNK_UPLOADER_AWS_REGION is preferred if both are set.
S3_ROOT_DIRECTORY
CHUNK_UPLOADER_S3_ROOT_DIRECTORY
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.
ClamAV
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 test.com rather than https://test.com
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(
max_length=10,
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.
Tests
$ pip install -r requirements.txt
$ tox
Project details
Release history Release notifications | RSS feed
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_chunk_upload_handlers-0.0.15.tar.gz
.
File metadata
- Download URL: django_chunk_upload_handlers-0.0.15.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc11267f6fca75e31d5726bea48172426b10a65e4a97e6bc72782e9c368bef5 |
|
MD5 | 5007f4f5ee33662b702e9599ab9f8a74 |
|
BLAKE2b-256 | ef1f835af6fc0b32a41830843579e59a6922f3490dd226a157b54cd9a48e0932 |
File details
Details for the file django_chunk_upload_handlers-0.0.15-py3-none-any.whl
.
File metadata
- Download URL: django_chunk_upload_handlers-0.0.15-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab19bba5b1c6efa484bea4fe8c4b1807d7e513abd89bcf8b4822c10495337bc5 |
|
MD5 | 3dc4a5593cd82a79a04e6ee4b74e9617 |
|
BLAKE2b-256 | 931592c402b814efbdf13f70ca5bf5e47eda8bf42be9555e1e555de87ede022e |