Reputation: 1199
I have a download link on one of my webpage in django. When i download a audio file of 75mb it downloads but nothing in the audio, its 0bytes.
this is my code:
from django.core.servers.basehttp import FileWrapper
import mimetypes
rec_file = settings.WEB_PATH + "/media/recording/" + filename
wrapper = FileWrapper( open(rec_file, "r"))
contentType = mimetypes.guess_type(rec_file)[0]
response = HttpResponse(wrapper, mimetype = "application/force-download")
response['Content-Length'] = os.path.getsize(rec_file)
response['Content-Disposition'] = "attachment; filename=" + filename
return response
i use apache server. can anyone tell me the solution ?
Upvotes: 1
Views: 279
Reputation: 53819
Couldn't say what's wrong with your code, but you shouldn't be doing that anyways. You should serve static files directly from Apache or use X-Sendfile.
Upvotes: 2