Reputation: 495
I use Primefaces p:fileUpload
dialog. When I use some specific Turkish characters in file name like "ğ ü ş ı ö ç" I can't get them corretly and can't save the uploaded file on disc.
public void handleFileUpload(FileUploadEvent event){
String newName = new String(event.getFile().getFileName("ISO-8859-1").getBytes(), "UTF-8");
or I also tried this one:
String newName = new String(event.getFile().getFileName("ISO-8859-1").getBytes(), "ISO-8859-9");
How to get or convert the letters corretly? Thanks for help.
Upvotes: 1
Views: 1211
Reputation: 28569
Make sure to include the following filter in your web.xml, before the file upload filter
<filter>
<filter-name>Character Encoding Filter</filter-name>
<filter-class>org.primefaces.examples.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Character Encoding Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
now simple event.getFile().getFileName()
should print the proper name
Upvotes: 1