django_auxilium.forms.files module¶
-
class
django_auxilium.forms.files.
TypedFileField
(*args, **kwargs)[source]¶ Bases:
django.forms.fields.FileField
Typed FileField which allows to make sure the uploaded file has the appropriate type.
File type can be verified either by extension and/or mimetype.
This field accepts all the parameters as FileField, however in addition it accepts some additional parameters as documented below.
Examples
TypedFileField(ext_whitelist=['jpg', 'jpeg'], type_whitelist=['image/jpeg'])
Warning
If
use_magic
is used, please make sure thatpython-magic
is installed. This library does not require it by default.Parameters: - ext_whitelist (list, optional) – List of allowed file extensions. Note that each extension
should emit the first period. For example for filename
'example.jpg'
, the allowed extension should be'jpg'
. - type_whitelist (list, optional) – List of allowed file mimetypes.
- use_magic (bool, optional) – If
type_whitelist
is specified, this boolean determines whether to usepython-magic
(based of top oflibmagic
) to determine the mimetypes of files instead of relying on Django’sUploadedFile.content_type
. Django does not take any real care to determine any accurately the mimetype so it is recommended to leave this parameter asTrue
which is the default value.
-
default_error_messages
= {u'extension': u'File extension is not supported.', u'mimetype': u'File mimetype is not supported.'}¶
- ext_whitelist (list, optional) – List of allowed file extensions. Note that each extension
should emit the first period. For example for filename