2 Replies Latest reply on Jun 8, 2011 8:29 PM by nbelaevski

    rich:fileUpload byte[] array is null

    georgemic

      I've looked up all discussions within richfaces pertaining to rich:fileUpload and couldn't find where there was any solution in RF3.3.3 where the rich:fileUpload functionality successfully calls the listener with a populated UploadEvent object where the event.getUploadItem().getData() attribute is null (after posting to the listener). I am using IE7, FF3.6.8, Tomcat 6 on a WinXP machine, RichFaces 3.3.3.Final, JSF1.2, Facelets-1.1.14. I am using the code from the demo website. Any help with this would be greatly appreciated. The code snippets are as follows...
      
      

       

      home.xhtml

      
      <rich:fileUpload fileUploadListener="#{myAppView.fileUploadListener}"
      id="upload"
      maxFilesQuantity="#{myAppView.uploadsAvailable}"
      immediateUpload="#{myAppView.autoUpload}"
      acceptedTypes="jpg, gif, png, bmp" allowFlash="#{myAppView.useFlash}">
      <a4j:support event="onuploadcomplete" reRender="info" />
      </rich:fileUpload>

       

      MyAppView.java

       

      
       
      
      public void fileUploadListener(UploadEvent event) {
           try {          String fileName = event.getUploadItem().getFileName();
                System.
      out.println("INSIDE fileUploadListener - " + fileName);          UploadItem item = event.getUploadItem();
      
                if (item != null && item.getData() != null) {               File fileData = 
      new File();               fileData.setData(item.getData());
                     fileData.setLength(item.getData().
      length);               fileData.setName(item.getFileName());
                     getFiles().add(fileData);
      
                     uploadsAvailable--;          } 
      else {               System.
      out.println("Byte data is null");          }
           } 
      catch(Exception e) {          e.printStackTrace();
           }
      }
      
       

       

      OUTPUT

       

      INSIDE fileUploadListener - C:\Documents and Settings\Michael\My Documents\My Pictures\87[1].gif
      Byte data is null
      
      
        • 1. Re: rich:fileUpload byte[] array is null
          georgemic

          My apologies, that wasn't posted correctly......

           

           

           

          I've looked up all discussions within richfaces pertaining to rich:fileUpload and couldn't find where there was any solution in RF3.3.3 where the rich:fileUpload functionality successfully calls the listener with a populated UploadEvent object where the event.getUploadItem().getData() attribute is null (after posting to the listener). I am using IE7, FF3.6.8, Tomcat 6 on a WinXP machine, RichFaces 3.3.3.Final, JSF1.2, Facelets-1.1.14. I am using the code from the demo website. Any help with this would be greatly appreciated.

           

          Here is the missing web.xml snippets too...

           

           

           

           

           

           

           

          <context-param>

           

          <param-name>createTempFiles</param-name>

           

          <param-value>true</param-value>

           

          </context-param>

           

           

          <context-param>

          <param-name>maxRequestSize</param-name>

           

          <param-value>1024000</param-value>

           

          </context-param>

           

          <context-param>

           

          <param-name>tempFilesDirectory</param-name>

           

          <param-value>d:</param-value>

           

          </context-param>

           

           

          • 2. Re: rich:fileUpload byte[] array is null
            nbelaevski

            Hi Michael,

             

            According to documentation, you should be using another method: http://docs.jboss.org/richfaces/latest_3_3_X/en/apidoc_framework/org/richfaces/model/UploadItem.html#getData()