Fix #857: Fix broken upload for specific files when using S3 storage
This commit is contained in:
parent
d52e804a3c
commit
0a25243e25
|
@ -12,7 +12,7 @@ def guess_mimetype(f):
|
||||||
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
|
# failure, we try guessing by extension
|
||||||
mt, _ = mimetypes.guess_type(f.path)
|
mt, _ = mimetypes.guess_type(f.name)
|
||||||
if mt:
|
if mt:
|
||||||
t = mt
|
t = mt
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -36,3 +36,12 @@ def test_get_audio_file_data(name, expected):
|
||||||
result = utils.get_audio_file_data(f)
|
result = utils.get_audio_file_data(f)
|
||||||
|
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_guess_mimetype_dont_crash_with_s3(factories, mocker, settings):
|
||||||
|
"""See #857"""
|
||||||
|
settings.DEFAULT_FILE_STORAGE = "funkwhale_api.common.storage.ASCIIS3Boto3Storage"
|
||||||
|
mocker.patch("magic.from_buffer", return_value="none")
|
||||||
|
f = factories["music.Upload"].build(audio_file__filename="test.mp3")
|
||||||
|
|
||||||
|
assert utils.guess_mimetype(f.audio_file) == "audio/mpeg"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix broken upload for specific files when using S3 storage (#857)
|
Loading…
Reference in New Issue