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

前端 未结 6 1454
误落风尘
误落风尘 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:35

    Answer (sort of) to problem #2:

    Since you've discovered that the naming scheme in one browser does not work in the other, your only solution is to do it differently for each browser, similar to the example here.

    In case the link goes away, the solution is basically:

    1. If browser is IE URL encode filename
    2. Generate Content-disposition header
    

    Of course determining if the browser is IE by User-agent (which is about the only way you can do it) is fraught with all sorts of the usual peril.

    As North American centric as this sounds, if it is important that this work in a large number of browsers you do not control which may have the User-agent blocked, or modified, then simply avoid UTF-8 encoded characters in the filename and always use "Download" or something.

提交回复
热议问题