title: Primefaces fileupload works only for the first file to be uploaded
body: <p>I am using Primefaces and I have an issue with the fileuploader. The problem is that it works fine with the first file I upload (the fileUploadListener is called and the java method uploads the file), but then if I try to upload another file, the listener is not called anymore and the java method is never triggered. If I refresh the page, I can upload another file but again if I try to upload a second one the same thing happens.</p>
  
  <p><b>code within the xhtml file:</b></p>
  
  <pre><code>&lt;p:tab id="eConsentTabPanel" title="Informed Consent" disabled="#{patientHandlerAction.patientTabsStatus}"&gt;
    &lt;h:form id="eConsentForm" enctype="multipart/form-data"&gt;
       &lt;h:panelGrid id="eConsentPanelGrid"&gt;
          &lt;p:fileUpload fileUploadListener="#{patientHandlerAction.handleFileUpload}" 
                        mode="advanced"
                        update="messages"
                        multiple="true"
                        auto="true"
                        sizeLimit="20971520"
                        label="Select File"
                        allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc?x)$/"/&gt;
          &lt;p:growl id="messages" showDetail="true"/&gt;  
       &lt;/h:panelGrid&gt;
    &lt;/h:form&gt;  
  &lt;/p:tab&gt;
  </code></pre>
  
  <p><b>code within the java bean file:</b></p>
  
  <pre><code>public void handleFileUpload(FileUploadEvent event) {
  
     ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
     String filename = FilenameUtils.getName(event.getFile().getFileName());
     File result = new File(extContext.getRealPath("//uploaded//" + filename));
  
     try {
        FileOutputStream fileOutputStream = new FileOutputStream(result);
  
        byte[] buffer = new byte[6124];
  
        int bulk;
        InputStream inputStream = event.getFile().getInputstream();
        while (true) {
           bulk = inputStream.read(buffer);
           if (bulk &lt; 0) {
              break;
           }
           fileOutputStream.write(buffer, 0, bulk);
           fileOutputStream.flush();
        }
  
        fileOutputStream.close();
        inputStream.close();
  
        messageTitle = "Message";
        messageBody = "The file" + event.getFile().getFileName() + " was succesfully uploaded!";
  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, messageTitle, messageBody));
  
     }
  
     catch (IOException e) {
        e.printStackTrace();
  
        messageTitle = "Message";
        messageBody = "The file was not uploaded";
  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, messageTitle, messageBody));
        FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR, "The files were not uploaded!", "");
        FacesContext.getCurrentInstance().addMessage(null, error);
     }
  
  }
  </code></pre>
  
  <p><b>code within the web.xml file:</b></p>
  
  <pre><code>&lt;filter&gt;
     &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
     &lt;filter-class&gt;
        org.primefaces.webapp.filter.FileUploadFilter
     &lt;/filter-class&gt;
     &lt;init-param&gt;
        &lt;param-name&gt;uploadDirectory&lt;/param-name&gt;
        &lt;param-value&gt;/HerEhrUploaded/temp&lt;/param-value&gt;
     &lt;/init-param&gt;
     &lt;init-param&gt;
        &lt;param-name&gt;thresholdSize&lt;/param-name&gt;
        &lt;param-value&gt;20971520&lt;/param-value&gt;
     &lt;/init-param&gt;      
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
     &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
     &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
  &lt;/filter-mapping&gt;
  </code></pre>