Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Uploading file with special characters in name

 
Kovacs Antal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am using the Apache Commons Fileupload tools for standard file upload. My problem is that I cannot get the proper filename of uploaded files if they contain special characters (á, é, ú, etc.) They all get converted to ? signs.

request.getCharacterEncoding() says UTF-8, but the bytes I get in the string fileItem.getName() are all the same for all my special characters.

Can you help me what's wrong?

(Some details: using Firefox 3.6.12, Weblogic 10.3 on Windows)

This is my code snippet:

 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure about this at all, never used it though,
but happened to see the API just now and found that there is "setHeaderEncoding" for ServletFileUpload and default value is not UTF-8 and also happened to see that it gets the file name from the header.
May be it may work, just give a try and set the header encoding to UTF-8 or whatever desired
 
Kovacs Antal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as I understand the browser tells the encoding of its message. I think when the request is parsed this should be considered when I ask for the fileItem's name at fileItem.getName().. The Apache javadoc also says for setHeaderEncoding: "When not specified, or null, the request encoding is used."

In my case the enc = request.getCharacterEncoding(); resulted in "UTF-8", so I think this is what the browser sends. But why the parser is unable to get the correct filename then.. ? :-(
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't clear to me why you think there is a problem. You have a lot of experimental code, it appears, but nothing which tells me what you looked at to determine that you thought there was a problem. Could you provide more information about how you looked at the file name in that code?
 
Kovacs Antal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debugging / logging shows me that fileItem.getName() gives me a String that contains ? marks at all places where special characters (á, é, ö, stb.) should be. Uploaded files can be downloaded later in my program, filenames are bad when downloaded too..
 
Kovacs Antal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all, the problem was solved by calling setHeaderEncoding("iso-8859-2") explicitly, as you suggested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic