Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5

I am using PrimeFaces v3.5 to upload the files in my windows machine using Firefox browser. event.getFile().getFileName() is returning filename with complete path which is causing problems further. Internally PrimeFaces is using Apache commons. I checked the javadoc also but not helping me anymore.

To overcome with this issue, I modified the program a little bit like following manner-

        String fileName = event.getFile().getFileName();
        fileName = fileName.substring(fileName.lastIndexOf("\\"));

But it's not robust and reliable. Any suggestions please?

like image 357
Ravi Joshi Avatar asked Dec 27 '22 06:12

Ravi Joshi


1 Answers

Commons IO offers FilenameUtils#getName() for the exact purpose.

String filename = FilenameUtils.getName(event.getFile().getFileName());

See also:

  • Commons FileUpload FAQ on the subject
  • How to save uploaded file in JSF
like image 175
BalusC Avatar answered May 21 '23 00:05

BalusC