Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces FileUpload Get File Extension

Tags:

primefaces

I'm using the primefaces fileUpload component and then I inspect the FileUploadEvent.getFile but I don't see a way to reliably get the extension. Any ideas?

like image 384
c12 Avatar asked Feb 24 '23 17:02

c12


1 Answers

getFile() returns an org.primefaces.model.UploadedFile object which has a method getFileName to return the file name. Then you can get the extension from the filename.

UploadedFile tfile = event.getFile();
String str = tfile.getFileName();
String ext = str.substring(str.lastIndexOf('.'), str.length());
like image 128
Mark Avatar answered Mar 18 '23 02:03

Mark