Search code examples
jsf-2.2omnifaces

OmniFaces inputFile case insensitive media type filtering


I'm using OmniFaces's 2.6.1 inputFile to upload files and want to apply media type filtering through the use of the accept attribute, for example accept="image/png". This works fine for file names having a .png extension, but is apparently case sensitive. When uploading a file with a .PNG extension, the validation fails. I tried specifying accept="image/PNG" and accept="image/*", but to no avail.

Is there an easy way to filter on media types in a case insensitive way?


Solution

  • Under the covers, the <o:inputFile> derives the mime type from the server's mime mapping, which you can control via <mime-mapping> entries in web.xml.

    I can't reproduce your problem on WildFly 12. Apparently you're using a server which doesn't perform case insensitive matching on the file extension.

    As per issue 447 I've fixed it for 2.6.9 by explicitly lowercasing the filename before consulting the server-managed mime mapping. For now, a work around is to explicitly add a mime mapping for PNG extension to your webapp's web.xml.

    <mime-mapping>
        <extension>PNG</extension>
        <mime-type>image/png</mime-type>
    </mime-mapping>
    

    Note that this still won't match Png, pNG, pNg, etc.