fileUpload block .exe upload

UI Components for JSF
Post Reply
CristianoPassos
Posts: 13
Joined: 17 Dec 2012, 15:13

16 Oct 2014, 22:46

Hi!

My doubt is quite simple, but unfortunately I was not able to solve it and didn't find the answer anywhere.

I've a page that allows the user to send a upload, I would like to BLOCK the upload only if the file has the .exe extension.

Every regex that I've thought about didn't work well, like:

^(?!.*\.exe$).*$
.*\.(exe)$
\.exe$

Thank you!
PrimeFaces: 5.0
JSF: Mojarra/2.2.6
Server: Wildfly 8.1.0.final

User avatar
ademkursatuzun
Posts: 21
Joined: 08 Apr 2013, 13:22

17 Oct 2014, 10:34

Post your code.Maybe you're missing something.You are using "allowTypes" for fileUploader aren't you ?
PrimeFaces 5.2 !|! Glassfish 4.0 !|! Mojarra 2.2.0 /
Mac Os X !|! Firefox 32.0
_______________________________________/
root@server:~f LLLSDLaserControl -ck 1 ]

CristianoPassos
Posts: 13
Joined: 17 Dec 2012, 15:13

20 Oct 2014, 12:17

ademkursatuzun wrote:Post your code.Maybe you're missing something.You are using "allowTypes" for fileUploader aren't you ?
Hi ademkursatuzun!

Yes, I'm using allowTypes:

Code: Select all

<p:fileUpload allowTypes="/^(?!.*\.exe$).*$/" fileUploadListener="#{feedbackController.handleFileUpload}" fileLimit="1" style="width:100%"	sizeLimit="8388608" />

I've tried all above options, with and without the regex between the slashes "/REGEX/":
^(?!.*\.exe$).*$
.*\.(exe)$
\.exe$
PrimeFaces: 5.0
JSF: Mojarra/2.2.6
Server: Wildfly 8.1.0.final

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

20 Oct 2014, 12:19

Things like allowedTypes work in any upload mode other than simple. In the case of simple you have to reject the uploaded file on the server side.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

CristianoPassos
Posts: 13
Joined: 17 Dec 2012, 15:13

28 Oct 2014, 13:51

andyba wrote:Things like allowedTypes work in any upload mode other than simple. In the case of simple you have to reject the uploaded file on the server side.

Thank's andyba, but how can I block the upload of .exe files using other mode rather than simple?
None of my regex is working, and when use something like

Code: Select all

allowTypes="/.*\.(exe)$/" 
, the component starts to block everything that I try to upload.

Code: Select all

<p:fileUpload allowTypes="/.*\.(exe)$/" fileUploadListener="#{feedbackController.handleFileUpload}" fileLimit="1" style="width:100%"	sizeLimit="8388608" mode="advanced" />
Image
PrimeFaces: 5.0
JSF: Mojarra/2.2.6
Server: Wildfly 8.1.0.final

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

29 Oct 2014, 16:31

Find a site that provides JavaScript regular expression testing and get your regex right.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests