Skip to content

Commit 2cd6989

Browse files
authored
Merge pull request #13 from epicfaace/master
Windows support for magic
2 parents 09b62d1 + d93fd30 commit 2cd6989

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Installation
2222

2323
* Download and install package with python setup.py install.
2424
* Note that this package depends on python-magic (to check field types).
25+
* For windows, you must download the dll files and .magic file at https://github.com/pidydx/libmagicwin64 (32-bit version: http://gnuwin32.sourceforge.net/packages/file.htm)), add them to C:\\Windows\\System32 (or to a folder in your PATH), and set MAGIC_FILE_PATH="..." to the path of your .magic file in your settings.py. For more information about the files to download, go to: https://github.com/ahupp/python-magic/blob/43df08c5ed63d7aad839695f311ca1be2eeb1ecb/README.md#dependencies
2526
* Add 'validatedfile' to your INSTALLED_APPS in settings.py.
2627

2728
Validate single file

validatedfile/fields.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django import forms
33
from django.template.defaultfilters import filesizeformat
44
from django.utils.translation import ugettext as _
5+
from django.conf import settings
56

67
import magic
78

@@ -20,7 +21,11 @@ def clean(self, *args, **kwargs):
2021
if self.content_types:
2122
uploaded_content_type = getattr(file, 'content_type', '')
2223

23-
mg = magic.Magic(mime=True)
24+
magic_file_path = getattr(settings, "MAGIC_FILE_PATH", None)
25+
if magic_file_path:
26+
mg = magic.Magic(mime=True, magic_file=magic_file_path)
27+
else:
28+
mg = magic.Magic(mime=True)
2429
content_type_magic = mg.from_buffer(
2530
file.read(self.mime_lookup_length)
2631
)

0 commit comments

Comments
 (0)