I want to download a file with Django's httpresponse
method. The name of the file has some special characters, like Chinese. I can download the file with the following code, but the file name appears as "%E6%B8%B8%E6%88%8F%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B3%A8%E5%86%8C%E9%A1%B5%E9%9D%A2.jpg".
Could anyone tell me how to convert the file name?
response = HttpResponse(attachment.file, content_type='text/plain',mimetype='application/octet-stream')
response['Content-Disposition'] = "attachment; filename="+urlquote(filename)
return response
Edit:
Another problem comes out when using smart_str
, the file name can be displayed normally in Firefox and Chrome, but not in IE: in IE it's still displaying some unknown characters. Does anyone know how to fix this problem?
Thanks in advance!
---solved by use urlquote
and smart_str
differently in IE and other browsers.