I wrote a function that generates some csv file on the fly and sends to user for download.
the code is below:
@app.route('/survey/<survey_id>/report')
def survey_downloadreport(survey_id):
survey, bsonobj = survey_get(survey_id)
resps = response_get_multi(survey_id)
fields = ["_id", "sid", "date", "user_ip"]
fields.extend(survey.formfields)
csvf = StringIO.StringIO()
wr = csv.DictWriter(csvf, fields, encoding = 'cp949')
wr.writerow(dict(zip(fields, fields)))
for resp in resps :
wr.writerow(resp)
csvf.seek(0)
now = datetime.datetime.now()
report_name = survey.name + "(" + \
now.strftime("%Y-%m-%d-%H:%M:%S") +\
")" + ".csv"
report_name = report_name.encode("utf-8")
return send_file(csvf,
as_attachment = True,
attachment_filename = report_name)
as you can see, the filename is converted from unicode to string and in utf-8 (to be precise, they are in Korean letters.)
the problem is, filenames are completely broken in when page is viewed in IE(no problem in chrome).
It seems like the header has to be edited to match parsing rules for different browsers, but I have no idea how I can do this in flask.
Try adding
to send_file.