[Answer]-HttpResponse content type for csv and other extentions doesn't work in firefox but works in Chrome and IE

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.

👤wdahab

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

Leave a comment