cancel
Showing results for 
Search instead for 
Did you mean: 

How to encode filename of FileUpload UI element

Former Member
0 Kudos

Hi everyone,

I used FileUpload element to upload file to KM folder.<b> It works fine for the English filename, but fails to work for the non-English filename. (Chinese filename</b>). How do I encode the filename to be recognized by the FileUpload API. A piece of my code is as follows:

WDAttributeInfo attInfo = wdContext.nodeFileUpload().getNodeInfo().getAttribute("FileResource");

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();

String mineType = binaryType.getMimeType().toString();

byte[] fileData = wdContext.currentFileUploadElement().getFileResource();

File file = new File(binaryType.getFileName());

/Create an output stream for writing to the temperory location/

FileOutputStream out = new FileOutputStream(file);

out.write(fileData);

out.flush();

out.close();

/From the temporary location read the file using an input stream/

FileInputStream fin = new FileInputStream(".//"+file);

<b>binaryType.getFileName() gives me the wrong encoding characters.</b>

Please advice me how to solve this....thanks a lot.

Zita

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I finally found a forum to solve this problem. Here is the link:

I followed Omer Shem-tov 's solution.

former_member182294
Active Contributor
0 Kudos

Hi Zita,

Try this...

String fileName = new String(binaryType.getFileName().getBytes(),"UTF-8");

File file = new File(fileName);

If charset <b>UTF-8</b> doesnt work then you can try <b>iso-2022-cn</b> which is for Chinese charset.

Regards

Abhilash

Former Member
0 Kudos

Hi Abhilash,

Thank you for your reply, but none of them is working....

I tried:

fileName = new String(binaryType.getFileName().getBytes((String)System.getProperties().get("file.encoding")), "Big5");

fileName = new String(binaryType.getFileName().getBytes(), "Big5");

fileName = new String(binaryType.getFileName().getBytes(), "iso-2022-cn");

fileName = new String(binaryType.getFileName().getBytes(), "UTF-8");

Any other method???

thanks,

Zita

former_member182294
Active Contributor
0 Kudos

Hi Zita,

I am not sure if binaryType.getFileName().getBytes() is returning the file name in proper format. I used same method in Java and it was working fine.

Regards

Abhilash

Former Member
0 Kudos

Hi,

binaryType.getFileName() return String. If the file name is English, it will return English filename correctly. If getBytes() is removed from this line, then it will have an error, saying that Constructor String(string,string) is undefined.

Any advice.

thanks,

Zita