我有HTTP头的问题,它们是用ASCII编码的,我想提供一个用于下载文件的视图,名称可以是非ASCII。
response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )我不想使用与非ASCII文件名相同问题的静态文件,但在这种情况下,文件系统和文件名编码会出现问题。 (我不知道目标os。)
我已经尝试过urllib.quote(),但它引发了KeyError异常。
可能我在做错事,但也许是不可能的。
I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII.
response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )I don't want to use static files serving for same issue with non ASCII file names but in this case there would be a problem with File system and it's file name encoding. (I don't know target os.)
I've already tried urllib.quote(), but it raises KeyError exception.
Possibly I'm doing something wrong but maybe it's impossible.
最满意答案
这是一个FAQ。
没有可互操作的方式来做到这一点。 一些浏览器实现专有扩展(IE,Chrome),其他实现RFC 2231(Firefox,Opera)。
请参见http://greenbytes.de/tech/tc2231/的测试用例。
更新:截至2012年11月,所有当前的桌面浏览器都支持RFC 6266和RFC 5987(Safari> = 6,IE> = 9,Chrome,Firefox,Opera,Konqueror)中定义的编码。
This is a FAQ.
There is no interoperable way to do this. Some browsers implement proprietary extensions (IE, Chrome), other implement RFC 2231 (Firefox, Opera).
See test cases at http://greenbytes.de/tech/tc2231/.
Update: as of November 2012, all current desktop browsers support the encoding defined in RFC 6266 and RFC 5987 (Safari >= 6, IE >= 9, Chrome, Firefox, Opera, Konqueror).
如何编码HTTP标头的UTF8文件名?(How to encode UTF8 filename for HTTP headers? (Python, Django))我有HTTP头的问题,它们是用ASCII编码的,我想提供一个用于下载文件的视图,名称可以是非ASCII。
response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )我不想使用与非ASCII文件名相同问题的静态文件,但在这种情况下,文件系统和文件名编码会出现问题。 (我不知道目标os。)
我已经尝试过urllib.quote(),但它引发了KeyError异常。
可能我在做错事,但也许是不可能的。
I have problem with HTTP headers, they're encoded in ASCII and I want to provided a view for downloading files that names can be non ASCII.
response['Content-Disposition'] = 'attachment; filename="%s"' % (vo.filename.encode("ASCII","replace"), )I don't want to use static files serving for same issue with non ASCII file names but in this case there would be a problem with File system and it's file name encoding. (I don't know target os.)
I've already tried urllib.quote(), but it raises KeyError exception.
Possibly I'm doing something wrong but maybe it's impossible.
最满意答案
这是一个FAQ。
没有可互操作的方式来做到这一点。 一些浏览器实现专有扩展(IE,Chrome),其他实现RFC 2231(Firefox,Opera)。
请参见http://greenbytes.de/tech/tc2231/的测试用例。
更新:截至2012年11月,所有当前的桌面浏览器都支持RFC 6266和RFC 5987(Safari> = 6,IE> = 9,Chrome,Firefox,Opera,Konqueror)中定义的编码。
This is a FAQ.
There is no interoperable way to do this. Some browsers implement proprietary extensions (IE, Chrome), other implement RFC 2231 (Firefox, Opera).
See test cases at http://greenbytes.de/tech/tc2231/.
Update: as of November 2012, all current desktop browsers support the encoding defined in RFC 6266 and RFC 5987 (Safari >= 6, IE >= 9, Chrome, Firefox, Opera, Konqueror).
发布评论