1๐
โ
I have no idea why this worked, but my code is now working like this:
class AudioFetchView(View):
def get(self, request, audio_id, *args, **kwargs):
audio_file = UploadAudio.objects.get(pk=audio_id)
with open(audio_file.absolute_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type='audio/mpeg')
response['Content-Disposition'] = 'attachment; filename=%s' % audio_file.path
response['Accept-Ranges'] = 'bytes'
response['X-Sendfile'] = audio_file.path
response['Content-Length'] = os.path.getsize(audio_file.absolute_path)
return response
audio_fetch = AudioFetchView.as_view()
HTML:
<audio id="audio" src={{audio_fetch_url}} type="audio/mpeg"> </audio>
Figured Iโd post in case anyone finds this in the future.
๐คJosh
Source:stackexchange.com