[Catalyst] Re: Content Disposition filename
orasnita at gmail.com
Wed Dec 4 07:31:33 GMT 2013
From: Bill Moseley =
On Tue, Nov 19, 2013 at 10:32 AM, Bill Moseley <moseley at hank.org> wrote:
Anyone aware of a good, portable way in Perl to encode the filename in =
a Content-Disposition header? I would like to support UTF8 filenames, but s=
upport in browsers is unclear (if not changing).
Is this complexity something that the Catalyst framework should handle?=
It's one of those areas where it's easy to get wrong (I can see many dif=
ferent approaches in our own code).
I have no idea what the client can accept or what its OS uses as a path-s=
eparator, and I don't want to go down the client-sniffing path, anyway.
I have a user-supplied character string that I want to use as the filenam=
e, which I have to assume can contain any unicode character since it's user=
From my limited tests it seems most modern browsers are supporting the "f=
ilename*" extension. Each browser does some special handling (like replac=
ing the path-separator, or adding a file extension based on content-type if=
no file extension is in the filename).
All I want to do is make valid HTTP headers and let the client decide how=
to handle it, but also provide a usable filename (not just underscores, fo=
So, all I'm after is to make this valid markup:
$c->res->header( content_disposition =3D>
qq[attachment; filename=3D"$ascii_file"; filename*=3DUTF-8''$ut=
The filename* is easy, I'm finding:
my $utf8_file =3D uri_escape( Encode::encode( 'UTF-8' =3D> $filename ) =
But the $ascii_file is a bit more work. Percent-encoding doesn't work. =
So, have to do a bit of filtering.
See any easier/cleaner/more-correct approach? When I see this much code=
I tend to think it's the wrong approach.
You can use Text::Unidecode if you want to replace special chars with A=
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Catalyst