Hi Zsolt,

I wrote this reply in response to the same problem but in a different thread. I couldn't find it in the struts mailing list archives, so I include it again with the message it responds to. Someone has since written to me confirming that this does work.

-----------------------------

Yes, I think you are right, i didn't realise which class we were talking about there. I have just read a bit more about the Struts FileUpload and how it wraps commons upload. Assuming Commons Upload works correctly with the setHeaderEncoding, then I guess there might be work around.

Struts will use org.apache.struts.upload.CommonsMultipartRequestHandler by default to handle extracting the parameters out of the request and populating the form. It uses the DiskFileUpload class from Commons FileUpload. It is that handler that we need to modify, to do that we could create our own using the org.apache.struts.upload.CommonsMultipartRequestHandler source as the basis.

We need to tell Struts to use ours instead of the defualt by adding this to your struts-config.xml

<controller multipartClass="my.own.MultiPartClassHandler" />

Then to modify org.apache.struts.upload.CommonsMultipartRequestHandler by creating our my.own.MultiPartClassHandler class.
We need to modify the handleRequest() method like so:


 // Create and configure a DIskFileUpload instance.
 DiskFileUpload upload = new DiskFileUpload();

upload.setHeaderEncoding("UTF-8");

 // Set the maximum size before a FileUploadException will be thrown.
 upload.setSizeMax((int) getSizeMax(ac));
 ...

This is all untested and off the top of my head, so there is likely to be a mistake there somewhere, but I think it is possible.


Daniel Rabe wrote:



I see a similar problem with file upload. It doesn't look like
org.apache.strugs.upload.FormFile exposes a setHeaderEncoding method...

Daniel Rabe

-----Original Message-----
From: Jason Lea [mailto:[EMAIL PROTECTED] Sent: Friday, December 26, 2003 1:33 PM
To: Struts Users Mailing List
Subject: Re: What is wrong with this upload filename (UTF-8) decoding?



I have not used the file upload yet, but I believe you need to set the encoding for the headers


formFile.setHeaderEncoding("UTF-8")

setHeaderEncoding does this:
"Specifies the character encoding to be used when reading the headers of individual parts. When not specified, or |null|, the platform default encoding is used."
If this was running on a English operating system it is probably defaulting to the Latin-1 encoding.


From this Java Doc:
http://jakarta.apache.org/commons/fileupload/apidocs/org/apache/commons/file
upload/FileUploadBase.html#setHeaderEncoding(java.lang.String)

Please post back to the forum if this works. I would be interested in the result.

Zsolt Koppany wrote:





Hi,

my application has to support UTF-8 including when files are uploaded with UTF-8 characters in the filename (for example: ??????????????.txt).

I use a servlet filter that always call
request.setCharacterEncoding("UTF-8") and my jsp pages contain response.setContentType("text/html; charset=UTF-8");


Everything works fine except that I have problems with decoding of the name of uploaded filenames.

I use the code below to get the name of the uploaded filename:

String nm = formFile.getFileName();
String filename = new String(nm.getBytes(), "UTF-8");

The code above converts only the first couple of characters correctly
(result: ??????????????????????.txt).

Any ideas how to fix the problem?

I use TC-4.1.29, Struts-1.1, jdk1.4.2_02 Windows-XP.

Zsolt



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]















-- Jason Lea



Zsolt Koppany wrote:

Hi Colm,

I know that article, and as I wrote the application does work fine with
UTF-8 characters except upload.

Zsolt



-----Original Message-----
From: Colm Garvey [mailto:[EMAIL PROTECTED]
Sent: Friday, March 19, 2004 4:20 PM
To: Struts Users Mailing List
Subject: RE: UTF-8 characters in the name of the uploaded document


In this article:


http://www.anassina.com/struts/i18n/i18n.html

The author mentions that a filter is required for UTF-8 encoded forms.
Worth a go?

Colm

-----Original Message-----
From: Zsolt Koppany [mailto:[EMAIL PROTECTED]
Sent: 19 March 2004 14:22
To: Struts Users Mailing List
Subject: UTF-8 characters in the name of the uploaded document


Hi,


I use struts-1.1 with tomcat-4.1.30 and cannot get the name of
the uploaded
document correctly if that contains UTF-8 (Asian) characters. The
application itself does work fine with UTF-8 characters in forms etc. the
only exception is upload. Is there a fix to solve this problem or
will it be
fixed in the next release?

Zsolt



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]








--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to