p:fileUpload validateContentType=true doesn't work for xlsx if using mime-type

UI Components for JSF
Post Reply
OneMG
Posts: 10
Joined: 19 Sep 2019, 13:32

18 Jan 2022, 23:43

I'm using Primefaces 10.0.7. I have a file upload component that looks like this:

Code: Select all

<p:fileUpload id="upload" listener="#{reportUploadHandler.handleFileUpload}" label="Choose"
                              mode="advanced" auto="true" widgetVar="upldWV" update="upldPnl, messageList"
                              sizeLimit="5242880" allowTypes="/(\.|\/)(xlsx|pdf)$/i" virusScan="true"
                              validateContentType="true"
                              accept="application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" invalidFileMessage="This file type is not accepted" />
I want to use mime-type instead of tika since it's much smaller, but I'm unable to get it to accept xlsx files unless I include application/zip within accept. I can do that, but then users will see zip files when selecting a file as they are no longer filtered out. I saw an issue in the mime-type project page https://github.com/overview/mime-types/issues/11 that explains why the xlsx is application/zip, and it seems as if this is intended functionality of mime-type. Is this something that can possibly be fixed within the file upload component?

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

24 Jan 2022, 14:36

No the "Mime" checker is just a plugin we defer to the library like Tika or Mime Types not something we want to hard code into FileUpload.

The reason Mime Types is smaller is because of this and its the reason Tika is so massive as it has to include POI to figure out these MS Office docs. So your choice would be to use POI unfortunately.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests