1👍
Answer to an old question, I know, but the actual issue is that you didn’t enclose the filename with double quotes (and it has to be double, not single). IE and Chrome will read until the end of the line, but Firefox will read until the first space and stop.
So just change response['Content-Disposition'] = "attachment; filename=" + entry.name
to response['Content-Disposition'] = 'attachment; filename="%s"'%(entry.name)
and you’re set.
0👍
Based on django.views.static
:
import mimetypes
import os
import stat
from django.http import HttpResponse
statobj = os.stat(fullpath)
mimetype, encoding = mimetypes.guess_type(fullpath)
mimetype = mimetype or 'application/octet-stream'
with open(fullpath, 'rb') as f:
response = HttpResponse(f.read(), mimetype=mimetype)
if stat.S_ISREG(statobj.st_mode):
response["Content-Length"] = statobj.st_size
if encoding:
response["Content-Encoding"] = encoding
response['Content-Disposition'] = 'inline; filename=%s'%os.path.basename(fullpath)
return response
- [Answer]-Django – Add another model without Popup
- [Answer]-Celery worker not able to access files created by Django application on Heroku
- [Answer]-Django: Form errors with next parameter
Source:stackexchange.com