3 Replies Latest reply on Apr 16, 2014 10:58 AM by michpetrov

    Richfaces 4, rich:fileUpload error with the inputStream

    ivanlch08

      Hola,

       

      I have the following error with the component rich:fileUpload.

       

      I have this fileListener:

      private UploadedFile item;

      public void fileListener(FileUploadEvent event) {

           item = event.getUploadedFile();

      }//listener


      works fine.


      but after upload the file, I have a method executed by a h:commandButton, that convert the inputStream into a File:

      private File streamToFile( UploadedFile upFile ){

        File temp = prepareTempFile();

        if(temp != null && temp.exists()) {

                  try {

                  InputStream inputStream = upFile.getInputStream();     //exception

                      if(saveToFile(inputStream, temp)) {

                          return temp;

                      }

                  } catch (Exception ex) {

                  ex.printStackTrace();

                  }

              }

        return null;

        }

       

      It throws an Exception in this line:

                  InputStream inputStream = upFile.getInputStream();     //exception

       

      this is the trace:

      java.io.FileNotFoundException: D:\Ivan\desarrollo\jboss-as-7.1.1.Final\standalone\tmp\work\jboss.web\default-host\svr\richfaces_uploaded_file_2231567571047239373.tmp (El sistema no puede encontrar el archivo especificado)

      (file not found).

       

      I resolve this in a strange way, I add to the listener the following line:

      private UploadedFile item;

      public void fileListener(FileUploadEvent event) {

           item = event.getUploadedFile();

           InputStream inputStream = upFile.getInputStream();// this solve the problem, just call method getInputStream()

      }//listener


      but I want to know why this happen, and if exist another solution. maybe I'm missing some configuration.


      Thank you.


      Iván.