How to display a non-ascii filename in the file download box in browsers?

前端 未结 6 1476
误落风尘
误落风尘 2020-12-19 04:52

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-dis

6条回答
  •  星月不相逢
    2020-12-19 05:41

    The specs basically don't permit anything other than US-ASCII. HTTP headers are US-ASCII. HTTP's payload defaults to ISO 8859-1 but that refers to the content body, not the headers.

    Arguably the Right Thing to do would be to use MIME's technique for encoding non-ASCII data in headers, as described in RFC 2047, but I have no idea whether browsers actually support that.

    EDIT: Whoops, no, RFC 2047 section 5 explicitly says that the encoded form is not permitted in Content-Disposition. Looks like you're out of luck - there is no standard.

    EDIT 2: There is a standard - RFC 2231 defines how this is now supposed to work. It has support from some browsers, but is not supported in IE. I found some test cases which demonstrate how it works and what browser support is available.

提交回复
热议问题