Secure file field, which allows you to restrict uploaded file extensions.
Project description
django-safe-filefield
=====================
.. image:: https://travis-ci.org/mixkorshun/django-safe-filefield.svg?branch=master
:alt: build status
:target: https://travis-ci.org/mixkorshun/django-safe-filefield
.. image:: https://codecov.io/gh/mixkorshun/django-safe-filefield/branch/master/graph/badge.svg
:alt: code coverage
:target: https://codecov.io/gh/mixkorshun/django-safe-filefield
.. image:: https://badge.fury.io/py/django-safe-filefield.svg
:alt: pypi
:target: https://pypi.python.org/pypi/django-safe-filefield
.. image:: https://img.shields.io/badge/code%20style-pep8-orange.svg
:alt: pep8
:target: https://www.python.org/dev/peps/pep-0008/
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
:alt: MIT
:target: https://opensource.org/licenses/MIT
Secure file field, which allows you to restrict uploaded file extensions.
It may be useful for user-uploaded files (attachments).
This package adds model and forms field. What this fields does:
* restricts allowed file extensions (for example: only *.pdf files)
* checks file extensions is correct for sent content-type
* checks sent content type is correct for file content (detects by `libmagic`)
* checks uploaded file with anti-virus software
Installation
------------
The package can be installed using:
.. code-block::
pip install django-safe-filefield
Add the following settings:
.. code-block:: python
INSTALLED_APPS += (
'safe_filefield',
)
**django-safe-filefield** require `libmagic` to be installed.
Usage
-----
Simply add field to your model:
.. code-block:: python
from safe_filefield.models import SafeFileField
class MyModel(models.Model):
attachment = SafeFileField(
allowed_extensions=('xls', 'xlsx', 'csv')
)
Or to directly to your form:
.. code-block:: python
from safe_filefield.forms import SafeFileField
class MyForm(forms.Form):
attachment = SafeFileField(
allowed_extensions=('xls', 'xlsx', 'csv')
)
ClamAV support
--------------
.. note:: To use this functionality you should have `clamd` daemon.
This package have ability to check uploaded file with ClamAV antivirus.
To use anti-virus protection simply enable it in your form or model definition:
.. code-block:: python
from safe_filefield.forms import SafeFileField
class MyForm(forms.Form):
attachment = SafeFileField(
scan_viruses=True,
)
You can configure some ClamAV settings:
.. code-block:: python
CLAMAV_SOCKET = 'unix://tmp/clamav.sock' # or tcp://127.0.0.1:3310
CLAMAV_TIMEOUT = 30 # 30 seconds timeout, by default None which means infinite
Contributing
------------
If you have any valuable contribution, suggestion or idea,
please let me know as well because I will look into it.
Pull requests are welcome.
=====================
.. image:: https://travis-ci.org/mixkorshun/django-safe-filefield.svg?branch=master
:alt: build status
:target: https://travis-ci.org/mixkorshun/django-safe-filefield
.. image:: https://codecov.io/gh/mixkorshun/django-safe-filefield/branch/master/graph/badge.svg
:alt: code coverage
:target: https://codecov.io/gh/mixkorshun/django-safe-filefield
.. image:: https://badge.fury.io/py/django-safe-filefield.svg
:alt: pypi
:target: https://pypi.python.org/pypi/django-safe-filefield
.. image:: https://img.shields.io/badge/code%20style-pep8-orange.svg
:alt: pep8
:target: https://www.python.org/dev/peps/pep-0008/
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
:alt: MIT
:target: https://opensource.org/licenses/MIT
Secure file field, which allows you to restrict uploaded file extensions.
It may be useful for user-uploaded files (attachments).
This package adds model and forms field. What this fields does:
* restricts allowed file extensions (for example: only *.pdf files)
* checks file extensions is correct for sent content-type
* checks sent content type is correct for file content (detects by `libmagic`)
* checks uploaded file with anti-virus software
Installation
------------
The package can be installed using:
.. code-block::
pip install django-safe-filefield
Add the following settings:
.. code-block:: python
INSTALLED_APPS += (
'safe_filefield',
)
**django-safe-filefield** require `libmagic` to be installed.
Usage
-----
Simply add field to your model:
.. code-block:: python
from safe_filefield.models import SafeFileField
class MyModel(models.Model):
attachment = SafeFileField(
allowed_extensions=('xls', 'xlsx', 'csv')
)
Or to directly to your form:
.. code-block:: python
from safe_filefield.forms import SafeFileField
class MyForm(forms.Form):
attachment = SafeFileField(
allowed_extensions=('xls', 'xlsx', 'csv')
)
ClamAV support
--------------
.. note:: To use this functionality you should have `clamd` daemon.
This package have ability to check uploaded file with ClamAV antivirus.
To use anti-virus protection simply enable it in your form or model definition:
.. code-block:: python
from safe_filefield.forms import SafeFileField
class MyForm(forms.Form):
attachment = SafeFileField(
scan_viruses=True,
)
You can configure some ClamAV settings:
.. code-block:: python
CLAMAV_SOCKET = 'unix://tmp/clamav.sock' # or tcp://127.0.0.1:3310
CLAMAV_TIMEOUT = 30 # 30 seconds timeout, by default None which means infinite
Contributing
------------
If you have any valuable contribution, suggestion or idea,
please let me know as well because I will look into it.
Pull requests are welcome.
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
Built Distribution
Close
Hashes for django-safe-filefield-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22ea14c6037ce04a01e08f633aae17a96c56539aaf8d448349d5a5dd26652ac5 |
|
MD5 | c0ec48dbc6b2c46185af5c1b0acf7e41 |
|
BLAKE2b-256 | 0501f71c0a692f451af599cedc0e41ff1f5f09f2301d30ded3e521b109bb3f9c |
Close
Hashes for django_safe_filefield-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24270ef27e1a6fd0f39b7cd1d952d5d2ae9335a9409db8cb4fffeb9e07fc3fee |
|
MD5 | a7313083914d8d7f884b7504f7b11bb8 |
|
BLAKE2b-256 | 06186bdb21a528b3d14fb433fd2105a0ad66881616c849c1d299764dec223fd4 |