Fixed #73: broken file upload

This commit is contained in:
Eliot Berriot 2018-02-26 18:27:41 +01:00
parent 8283a73a7f
commit 8c7e943013
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
4 changed files with 32 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import magic
import mimetypes
import re
from django.db.models import Q
@ -42,7 +43,13 @@ def get_query(query_string, search_fields):
def guess_mimetype(f):
b = min(100000, f.size)
return magic.from_buffer(f.read(b), mime=True)
t = magic.from_buffer(f.read(b), mime=True)
if t == 'application/octet-stream':
# failure, we try guessing by extension
mt, _ = mimetypes.guess_type(f.path)
if mt:
t = mt
return t
def compute_status(jobs):