primefaces fileupload invalid file type doc, docx

user2354035 picture user2354035 · Jul 18, 2013 · Viewed 24.5k times · Source

I want to upload doc or docx file using primefaces fileUpload,although I specify the type of file it display Invalid file type

enter image description here

<p:fileUpload cancelLabel="#{contenu.annuler}"
    fileUploadListener="#{utilAdminBean.fileUpload}"
    allowTypes="/(\.|\/)(doc|docx)$/"
    multiple="false" mode="advanced" sizeLimit="52428800"
    showButtons="false" />

Answer

user2354035 picture user2354035 · Jul 21, 2013

I found the solution,I forgot to add to the fileupload component inside <h:form nctype="multipart/form-data">

functional code is as follows:

<h:form id="formcontract" enctype="multipart/form-data" dir="rtl">
    <p:fileUpload cancelLabel="#{contenu.annuler}"
        fileUploadListener="#{utilAdminBean.fileUpload}"
        allowTypes="/(\.|\/)(doc|docx|xls|xlsx|pdf)$/"
        multiple="false" mode="advanced" sizeLimit="52428800"
        showButtons="false" />
</h:form>