[Catalyst] Re: Content Disposition filename
Octavian Rasnita
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).
http://greenbytes.de/tech/tc2231/
http://stackoverflow.com/questions/93551/how-to-encode-the-filename-par=
ameter-of-content-disposition-header-in-http
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=
-supplied data.
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=
r example).
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=
f8_file] );
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=
SCII chars.
Octavian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131204/2b307=
4aa/attachment.htm
More information about the Catalyst
mailing list