[FIX] mimetype

This commit is contained in:
Parthiv Patel committed 2022-09-20 12:37:47 +00:00
1 parent 84d396b4dc
commit e15662bf20
1 file changed
+12 -1
+12 -1
View File
@@ -179,7 +179,7 @@ else:
_guesser = ms.buffer
def guess_mimetype(bin_data, default=None):
mimetype = _guesser(bin_data)
mimetype = _guesser(bin_data[:1024])
# upgrade incorrect mimetype to official one, fixed upstream
# https://github.com/file/file/commit/1a08bb5c235700ba623ffa6f3c95938fe295b262
if mimetype == 'image/svg':
@@ -191,3 +191,14 @@ def neuter_mimetype(mimetype, user):
if wrong_type and not user._is_system():
return 'text/plain'
return mimetype
def get_extension(filename):
""" Return the extension the current filename based on the heuristic that
ext is less than or equal to 10 chars and is alphanumeric.
:param str filename: filename to try and guess a extension for
:returns: detected extension or ``
"""
ext = '.' in filename and filename.split('.')[-1]
return ext and len(ext) <= 10 and ext.isalnum() and '.' + ext.lower() or ''