6 Replies Latest reply on Jun 19, 2013 10:38 PM by jaikiran pai

    Cannot save file when deploying to JBoss AS through maven

    Humberto Ferreira da Luz Jr. Novice

      JBoss AS maven plugin deploys my web application to JBoss virtual filesystem (/tpm/vfs/).

       

      When I try to save a picture to the relative path I get:

       

      /home/hfluz/Servers/standalone 7.1.1/standalone/tmp/vfs/temp3081e1eb97c799e8/content-b5984e02f5b23513/images/tmp/200701500694.png (No such file or directory)

       

      According to James R. Perkins the issue happens because the java.io.file does not support VFS.

       

      I could save the picture using an absolute path, but primefaces imageCropper can only find images through relative paths.

       

       

      My method that tries to save the uploaded picture:

       

       

      public void carregarArquivo(FileUploadEvent event)
              throws FileNotFoundException, IOException {
          InputStream input = event.getFile().getInputstream();
          ServletContext servletContext = (ServletContext) FacesContext
                  .getCurrentInstance().getExternalContext().getContext();
          File arquivo = new File(servletContext.getRealPath("") + File.separator
                  + "images" + File.separator + "tmp" + File.separator
                  + numMatricula + ".png");
          OutputStream output = null;
          try {
              output = new FileOutputStream(arquivo);
              IOUtils.copy(input, output);
              System.out.println("Arquivo salvo com sucesso em "
                      + arquivo.getAbsolutePath());
              tmpFotoPath = "/images/tmp/" + numMatricula + ".png";
              IOUtils.copy(input, output);
              System.out.println("Arquivo salvo com sucesso em "
                      + arquivo.getAbsolutePath());
              tmpFotoPath = "/images/tmp/" + numMatricula + ".png";
          } finally {
              IOUtils.closeQuietly(output);
              IOUtils.closeQuietly(input);
          }
      }

       

       

      Is there any workaround to be able to save the image to application's relative path?