Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

URI escape Chinese characters on file download

by hankcoder (Scribe)
on Dec 07, 2017 at 21:08 UTC ( #1205117=perlquestion: print w/replies, xml ) Need Help??
hankcoder has asked for the wisdom of the Perl Monks concerning the following question:

This URI escape for Chinese character has being bugging me for quite sometime.

I have a filename saved in my data with mixed letters so as Chinese characters in base64 encoded. However, when I execute a file Download request, I unable to get the save file to appear back to original Chinese characters filename. I'm not sure if it can be done or not. For now, they are all in standard uri_escape.

I also tried using uri_escape_utf8 result still same. It will become something like "...chinese%20%27%E9%A1%B6%E9%A1%B6.....png". The original Chinese filename is "chinese '顶顶顶顶' & 123.png" just for testing.

In download script;

use URI::Escape; .... $fname = uri_escape($fname); .... print "Content-length: $fsize\n"; print "Content-Disposition: attachment; filename=$fname\n"; print "Content-Type: application/force-download;\n\n"; ....

The download script works fine. Just when download file that contain Chinese characters filename, I can't get it Save in Chinese characters. The filename stored in my data base64 are decoded properly.

Could someone please give me some suggestions or that is just the way how it works? Many thanks.

Replies are listed 'Best First'.
Re: URI escape Chinese characters on file download
by hippo (Canon) on Dec 07, 2017 at 22:15 UTC

    As per RFC 5987 you should use the unwieldy print "Content-Disposition: attachment; filename*=UTF-8''$fname\n"; on the uri_escaped filename instead.

      Thank you so much. That works exactly as I need. Reading thru the page RFC5987 gonna take me a while to digest ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1205117]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2018-07-21 06:23 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (444 votes). Check out past polls.