commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pradeep Selvaraj <pradeep.selva...@customware.net>
Subject [FILEUPLOAD] How to upload files with Japanese filenames?
Date Thu, 03 Sep 2009 11:58:03 GMT
Hello everyone,

I am using the FileUpload package to upload files and my JSP code looks like this…

-------------------------
DiskFileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);
List <FileItem> items = upload.parseRequest(request);

Iterator iter = items.iterator();
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();

    if (!item.isFormField()) {
        String fileName = item.getName();

            File uploadedFile = new File("C:\\temp\\uploaded\\" + fileName);
            try{
                  item.write(uploadedFile);           //this line fails
            }
            catch(Exception e)
            {
                  out.write(e.getLocalizedMessage());
            }
-------------------

The code above  does not work when the file names are in Japanese. The filename changes into
‘????.ext’ and thus becomes an illegal file name – hence the item.write(uploadedFile)
line  fails.

 If I would like to retain the original filename, what should I do to my code?

Thanks for your help.

Regards,
Pradeep


Please consider our environment before printing this email.
This e-mail and any files transmitted with it are privileged and confidential information
intended for the use of the addressee. The confidentiality and/or privilege in this e-mail
is not waived, lost or destroyed if it has been transmitted to you in error. If you have received
this e-mail in error you must (a) not disseminate, copy or take any action in reliance on
it; (b) notify itsupport@customware.net and the sender immediately; and (c) delete the original
e-mail.


Please consider our environment before printing this email.
This e-mail and any files transmitted with it are privileged and confidential information
intended for the use of the addressee. The confidentiality and/or privilege in this e-mail
is not waived, lost or destroyed if it has been transmitted to you in error. If you have received
this e-mail in error you must (a) not disseminate, copy or take any action in reliance on
it; (b) notify itsupport@customware.net and the sender immediately; and (c) delete the original
e-mail.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message