p:fileUpload allowType case insensitive

UI Components for JSF
Post Reply
nordvik
Posts: 4
Joined: 17 Jan 2013, 13:10

28 Feb 2013, 10:54

Hi,

My problem is rather quite simple to explain. I use

Code: Select all

p:fileUpload
component and I have this pattern

Code: Select all

allowTypes="/(\.|\/)(gif|jpe?g|png$/"
to determine which file is allowed and which is not. My problem occure when I want to add file with extension like e.g. "example.JPG". Unfortunately I can't turn off case sensitivity. Any ideas how to do this? I tried with "(?i)/(\.|\/)(gif|jpe?g|png$/" or even /(\.|\/)(gif|jpe?g|png|GIF|JPE?G|PNG$/" and it's not working. I'll be very grateful for help.

gonzalogomezgarcia
Posts: 1
Joined: 19 Sep 2013, 09:41

19 Sep 2013, 09:48

Hi,
I've just met the same issue as you and I hope is not too late for a solution
The regular expression defined in attribute allowType is not evaluated as a Java Regular Expression. It's evaluated as a Javascript Regular Expression. The correct definition for making the regular expression case-insensitive is "/(\.|\/)(gif|jpe?g|png$/i" (using the "i" character at the end of the regular expression after the last slash)
Regards

shedyk
Posts: 6
Joined: 29 Oct 2014, 09:14

29 Oct 2014, 09:57

Hi,

Adding the

Code: Select all

/i
works but the image preview does not show when the extension is in upper case

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:25

Image file extensions in caps are not standards conform and should be made lower case.
Thanks to Windows these abominations turn up all too often. Simply make your filenames all lowercase when saving them and check against allowed files case insensitively.
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

shedyk
Posts: 6
Joined: 29 Oct 2014, 09:14

30 Oct 2014, 17:23

Thanks Andy for the reply, however the files(pictures) are many and many more are brought in on a daily basis hence having to check their extension every time and change to lowercase before uploading is going to be hectic.

Is there no way the primefaces fileupload can preview the images regardless of the extension case.

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

30 Oct 2014, 18:12

I didn't say that the file extensions should be changed manually, you can do this 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

shedyk
Posts: 6
Joined: 29 Oct 2014, 09:14

12 Nov 2014, 11:40

Problem seems to be in the javascript and a member on Stackoverflow has provided a solution as showed below.
The problem in the file \META-INF\resources\primefaces\fileupload\fileupload.js Preview images are only available for png, jpg and gif files and for this there is a check:

Code: Select all

//preview
if($this.isCanvasSupported() && window.File && window.FileReader && $this.IMAGE_TYPES.test(file.name))
and pattern:

Code: Select all

IMAGE_TYPES: /(\.|\/)(gif|jpe?g|png)$/
As you can see in this place lacks the flag for case insensitive validation. So i manually add this flag

Code: Select all

IMAGE_TYPES: /(\.|\/)(gif|jpe?g|png)$/i
and preview started working as it should.
Patch for the same sent to Primefaces
https://code.google.com/p/primefaces/is ... il?id=7625

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests