4 Replies Latest reply on Jul 11, 2011 4:59 AM by Nicoletta Fan

    upload file into web directory

    Alejandro Pérez Newbie
      Hi, I need to upload images files, I try <s:fileUpload> component, and it works fine for me, but every example I find, saves the file to database and I need to do it into a web directory. Is this possible? Can somebody show me an example?

      thanks in advance
        • 1. Re: upload file into web directory
          Jhon  Alvarez Newbie

          Excuse me, could perform what you
          If so, you could put your SOLUTION, PLEASE?
          Is that I am having the same problem

          Thank you

          • 2. Re: upload file into web directory
            Michael Courcy Newbie

            This work for me

            public class UploadHandler {
                 FacesContext facesContext;
                 @Logger private Log log;
                 private byte[] file;      
                 public void handleUpload() throws IOException{
                      String path = ((ServletContext) facesContext.getExternalContext().getContext()).getRealPath("/my/files/dir");
                      File f = new File(path,"myFile.txt");
                      FileOutputStream fo = new FileOutputStream(f);
                 public byte[] getFile() {
                      return file;
                 public void setFile(byte[] file) {
                      this.file = file;

            and the form

            <h:form id="fooForm" enctype="multipart/form-data">
                       <s:fileUpload id="file" 
                        <h:commandButton id="upload" value="Upload !!" 

            But I don't recommand to use the  ....getRealPath(/my/files/dir);.... instead use a path that you configure in seam.properties.

            • 4. Re: upload file into web directory
              Nicoletta Fan Newbie

              Hi! I've tried the code suggested by Michael, same .java, same .xhtml, adding to the components.xml the following configuration

              <web:multipart-filter create-temp-files="true"

              The file it's always uploaded correctly, but it throws a null pointer exception on the line

              Maybe it'a a matter of file system permission, but I haven't found a good solution to this problem, has anyone experienced the same problem?