如何在浏览器的文件下载框中显示非ascii文件名? [英] How to display a non-ascii filename in the file download box in browsers?
问题描述
文件下载的标题通常看起来像
>内容处理:附件; filename =theasciifilename.doc
除非您在文件名参数中粉碎utf8编码的字符串,否则Firefox将处理好,而IE会抛出。 >
有一个 CodeProject上的文档,解释说编码文件名的方法
此文档将BảnKiểmKê.doc编码为B%e1%ba%a3n%20Ki%e1%bb%83m %20K%c3%aa.doc通过十六进制编码字节。
问题#1:该字符串中的第一个字符:ả的值为ả - 数字在十六进制,你得到%a3%1e。这个人怎么得到%e1%ba%a3? (我显然在这里丢了一些简单的东西)
问题#2:虽然IE承认了这个编码,但Firefox并没有!做什么?
对问题#1的回答:你是混淆Unicode和UTF-8。 ả的十六进制值为0xA31E,但不是UTF-8字符。在UTF-8中,字符需要三个字节, 0xE1 0xBA 0xA3
。对于非ASCII编码,URL编码定义不全,但是%e1%ba%a3是用于该字符的有效UTF-8编码。
There doesn't seem to be an accepted way of sending down a header parameter in non ascii format.
The header for file download usually looks like
Content-disposition: attachment; filename="theasciifilename.doc"
Except if you smash a utf8 encoded string in the filename parameter, Firefox will handle it fine, whereas IE will throw up.
There is a document on CodeProject that explains a method for encoding the filename.
This document encodes Bản Kiểm Kê.doc to B%e1%ba%a3n%20Ki%e1%bb%83m%20K%c3%aa.doc by hex encoding the bytes.
Problem #1: the first character in that string: ả has a value of ả -- encode that number in Hex and you get %a3%1e. How did this guy get %e1%ba%a3? (I'm obviously missing something simple here)
Problem #2: While IE acknowledges this encoding, Firefox doesn't! What to do?
Answer to question #1: You are confusing Unicode and UTF-8. The hex value of 'ả' is 0xA31E however that is not a UTF-8 character. In UTF-8 that character requries three bytes, 0xE1 0xBA 0xA3
. URL encoding is poorly defined for non-ascii encodings but %e1%ba%a3 is the valid UTF-8 encoding to use for that character.
这篇关于如何在浏览器的文件下载框中显示非ascii文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!