Page 1 of 1

fileUpload block .exe upload

Posted: 16 Oct 2014, 22:46
by CristianoPassos
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!

Re: fileUpload block .exe upload

Posted: 17 Oct 2014, 10:34
by ademkursatuzun
Post your code.Maybe you're missing something.You are using "allowTypes" for fileUploader aren't you ?

Re: fileUpload block .exe upload

Posted: 20 Oct 2014, 12:17
by CristianoPassos
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$

Re: fileUpload block .exe upload

Posted: 20 Oct 2014, 12:19
by andyba
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.

Re: fileUpload block .exe upload

Posted: 28 Oct 2014, 13:51
by CristianoPassos
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

Re: fileUpload block .exe upload

Posted: 29 Oct 2014, 16:31
by andyba
Find a site that provides JavaScript regular expression testing and get your regex right.