Answer the question
In order to leave comments, you need to log in
How to stream MP3 using Django?
Guys, if anyone came across - share your experience.
I can't figure out how to send a file to a template for processing using the Django StreamingHttpResponse class.
Let's say there is such a view:
import os
import mimetypes
from django.http import StreamingHttpResponse
from django.core.servers.basehttp import FileWrapper
def mp3(request):
the_file = '/some/file/song.mp3'
filename = os.path.basename(the_file)
chunk_size = 8192
response = StreamingHttpResponse(FileWrapper(open(the_file, 'rb'), chunk_size),
content_type=mimetypes.guess_type(the_file)[0])
response['Content-Length'] = os.path.getsize(the_file)
response['Content-Disposition'] = "attachment; filename=%s" % filename
return response
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question