Verified Commit 8c7e9430 authored by Agate's avatar Agate 💬

Fixed #73: broken file upload

parent 8283a73a
......@@ -4,6 +4,9 @@ Changelog
0.6 (Unreleased)
----------------
- Fixed broken file import due to wrong url (#73)
- More accurate mimetype detection
0.5.1 (2018-02-24)
------------------
......
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):
......
from funkwhale_api.music import utils
def test_guess_mimetype_try_using_extension(factories, mocker):
mocker.patch(
'magic.from_buffer', return_value='audio/mpeg')
f = factories['music.TrackFile'].build(
audio_file__filename='test.ogg')
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
def test_guess_mimetype_try_using_extension_if_fail(factories, mocker):
mocker.patch(
'magic.from_buffer', return_value='application/octet-stream')
f = factories['music.TrackFile'].build(
audio_file__filename='test.mp3')
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
......@@ -29,7 +29,7 @@
</button>
</div>
<div class="ui hidden divider"></div>
<p>
<p v-if="batch">
Once all your files are uploaded, simply head over <router-link :to="{name: 'library.import.batches.detail', params: {id: batch.id }}">import detail page</router-link> to check the import status.
</p>
<table class="ui single line table">
......@@ -73,7 +73,7 @@ export default {
data () {
return {
files: [],
uploadUrl: 'import-jobs/',
uploadUrl: '/api/v1/import-jobs/',
batch: null
}
},
......
Markdown is supported
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