Unverified Commit 989f6631 authored by Agate's avatar Agate 💬
Browse files

Fix #1165: Fixed broken mimetype detection during import

parent 08e94691
...@@ -874,7 +874,7 @@ class Upload(models.Model): ...@@ -874,7 +874,7 @@ class Upload(models.Model):
if self.audio_file: if self.audio_file:
self.mimetype = utils.guess_mimetype(self.audio_file) self.mimetype = utils.guess_mimetype(self.audio_file)
elif self.source and self.source.startswith("file://"): elif self.source and self.source.startswith("file://"):
self.mimetype = mimetypes.guess_type(self.source)[0] self.mimetype = utils.guess_mimetype_from_name(self.source)
if not self.size and self.audio_file: if not self.size and self.audio_file:
self.size = self.audio_file.size self.size = self.audio_file.size
if not self.checksum: if not self.checksum:
......
...@@ -18,12 +18,18 @@ def guess_mimetype(f): ...@@ -18,12 +18,18 @@ def guess_mimetype(f):
b = min(1000000, f.size) b = min(1000000, f.size)
t = magic.from_buffer(f.read(b), mime=True) t = magic.from_buffer(f.read(b), mime=True)
if not t.startswith("audio/"): if not t.startswith("audio/"):
# failure, we try guessing by extension t = guess_mimetype_from_name(f.name)
mt, _ = mimetypes.guess_type(f.name)
if mt: return t
t = mt
else:
t = EXTENSION_TO_MIMETYPE.get(f.name.split(".")[-1]) def guess_mimetype_from_name(name):
# failure, we try guessing by extension
mt, _ = mimetypes.guess_type(name)
if mt:
t = mt
else:
t = EXTENSION_TO_MIMETYPE.get(name.split(".")[-1])
return t return t
......
Fixed broken mimetype detection during import (#1165)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment