You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Strand <ma...@entcap.se> on 2005/11/29 17:37:11 UTC
Encode filename in http header
I've written a download service where I set the filename like this:
response.setHeader("Content-disposition", "attachment; filename=\""
+ filename + "\"");
It appears I have to encode non-ascii characters somehow, how do I do that?
--Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Encode filename in http header
Posted by Leonardo Quijano Vincenzi <le...@dtqsoftware.com>.
AFAIK, You should encode the file name using BASE64 or Quoted-printable
encoding:
Use commons-codec (it's probably in your classpath anyway):
http://jakarta.apache.org/commons/codec/
fileName = new QCodec("utf-8").encode(fileName);
String contentType = provider.getContentType();
String disposition =
(provider.isAttached() ? "attachment" : "inline");
response.setHeader(
"Content-Disposition", disposition + "; " +
"filename=\"" + fileName + "\"");
This is based on the RFC for representing non-ASCII file names in an
attachment.
--
Ing. Leonardo Quijano Vincenzi
DTQ Software
Patrick Casey wrote:
> Did you try:
>
> String foo = ("Content-disposition", "attachment; filename=\""
>
>> + filename + "\"";
>>
>
> String bar = java.net.URLEncoder.encode(foo);
> Reponse.setHeader(bar);
>
> --- Pat
>
>
>> -----Original Message-----
>> From: Martin Strand [mailto:martin.strand@entcap.se]
>> Sent: Tuesday, November 29, 2005 8:37 AM
>> To: tapestry-user@jakarta.apache.org
>> Subject: Encode filename in http header
>>
>> I've written a download service where I set the filename like this:
>>
>> response.setHeader("Content-disposition", "attachment; filename=\""
>> + filename + "\"");
>>
>> It appears I have to encode non-ascii characters somehow, how do I do
>> that?
>>
>> --Martin
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
RE: Encode filename in http header
Posted by Patrick Casey <pa...@adelphia.net>.
I couldn't answer that unfortunately; I usually just use the default
character encoding and it works for me. I suppose you could try alternate
encodings (UTF-8 is always a good place to start).
--- Pat
> -----Original Message-----
> From: Martin Strand [mailto:martin.strand@entcap.se]
> Sent: Tuesday, November 29, 2005 10:16 AM
> To: Tapestry users
> Subject: Re: Encode filename in http header
>
> The URLEncoder seems to make the filename look even messier. Should I use
> a specific character encoding?
>
> --Martin
>
> On Tue, 29 Nov 2005 18:13:44 +0100, Patrick Casey <pa...@adelphia.net>
> wrote:
>
> > Did you try:
> >
> > String foo = ("Content-disposition", "attachment; filename=\""
> >> + filename + "\"";
> >
> > String bar = java.net.URLEncoder.encode(foo);
> > Reponse.setHeader(bar);
> >
> > --- Pat
> >
> >> -----Original Message-----
> >> From: Martin Strand [mailto:martin.strand@entcap.se]
> >> Sent: Tuesday, November 29, 2005 8:37 AM
> >> To: tapestry-user@jakarta.apache.org
> >> Subject: Encode filename in http header
> >>
> >> I've written a download service where I set the filename like this:
> >>
> >> response.setHeader("Content-disposition", "attachment; filename=\""
> >> + filename + "\"");
> >>
> >> It appears I have to encode non-ascii characters somehow, how do I do
> >> that?
> >>
> >> --Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Encode filename in http header
Posted by Martin Strand <ma...@entcap.se>.
The URLEncoder seems to make the filename look even messier. Should I use
a specific character encoding?
--Martin
On Tue, 29 Nov 2005 18:13:44 +0100, Patrick Casey <pa...@adelphia.net>
wrote:
> Did you try:
>
> String foo = ("Content-disposition", "attachment; filename=\""
>> + filename + "\"";
>
> String bar = java.net.URLEncoder.encode(foo);
> Reponse.setHeader(bar);
>
> --- Pat
>
>> -----Original Message-----
>> From: Martin Strand [mailto:martin.strand@entcap.se]
>> Sent: Tuesday, November 29, 2005 8:37 AM
>> To: tapestry-user@jakarta.apache.org
>> Subject: Encode filename in http header
>>
>> I've written a download service where I set the filename like this:
>>
>> response.setHeader("Content-disposition", "attachment; filename=\""
>> + filename + "\"");
>>
>> It appears I have to encode non-ascii characters somehow, how do I do
>> that?
>>
>> --Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
RE: Encode filename in http header
Posted by Patrick Casey <pa...@adelphia.net>.
Did you try:
String foo = ("Content-disposition", "attachment; filename=\""
> + filename + "\"";
String bar = java.net.URLEncoder.encode(foo);
Reponse.setHeader(bar);
--- Pat
> -----Original Message-----
> From: Martin Strand [mailto:martin.strand@entcap.se]
> Sent: Tuesday, November 29, 2005 8:37 AM
> To: tapestry-user@jakarta.apache.org
> Subject: Encode filename in http header
>
> I've written a download service where I set the filename like this:
>
> response.setHeader("Content-disposition", "attachment; filename=\""
> + filename + "\"");
>
> It appears I have to encode non-ascii characters somehow, how do I do
> that?
>
> --Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org