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

    rich:fileUpload byte[] array is null

    Michael George Newbie

      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