Skip to content

Commit 4ffeac1

Browse files
committed
Replaced hard coded mime lookup length with kwarg variable
1 parent 32c13ca commit 4ffeac1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

validatedfile/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ValidatedFileField(models.FileField):
1212
def __init__(self, *args, **kwargs):
1313
self.content_types = kwargs.pop("content_types", [])
1414
self.max_upload_size = kwargs.pop("max_upload_size", 0)
15+
self.mime_lookup_length = kwargs.pop("mime_lookup_length", 4096)
1516
super(ValidatedFileField, self).__init__(*args, **kwargs)
1617

1718
def clean(self, *args, **kwargs):
@@ -22,7 +23,9 @@ def clean(self, *args, **kwargs):
2223
uploaded_content_type = getattr(file, 'content_type', '')
2324

2425
mg = magic.Magic(mime=True)
25-
content_type_magic = mg.from_buffer(file.read())
26+
content_type_magic = mg.from_buffer(
27+
file.read(self.mime_lookup_length)
28+
)
2629
file.seek(0)
2730

2831
# Prefere mime-type instead mime-type from http header

0 commit comments

Comments
 (0)