4 Replies Latest reply on Jun 17, 2010 8:10 AM by vasuki hn

    how to fetch file path while file uploading

    vasuki hn Newbie

      Hi All,

      I am parsing the spreadsheet in my application. I want to get the file path of the spreadsheet which i can send as an parameter to my parsing function.

      I have created a UploadFile.java and uploadfile.xhtml. I will attach my code here.

      package org.domain.user.session;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.international.StatusMessages;
      import org.hibernate.validator.Length;
      import  turnup.Util;
      public class UploadFile
          @Logger private Log log;
          @In StatusMessages statusMessages;
          private String value;
         public void uploadFile()
              // implement your business logic here
              log.info("uploadFile.uploadFile() action called with: #{uploadFile.value}");
              statusMessages.add("uploadFile #{uploadFile.value}");
              String v2 = value;
          // add additional action methods
          @Length(max = 10000)
          public String getValue()
              return value;
          public void setValue(String value)
              this.value = value;

      xhtml file

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      <ui:define name="body">
          <h:form id="uploadFileForm" enctype="multipart/form-data">
                  <f:facet name="header">UploadFile</f:facet>
                  <s:decorate id="value" template="layout/edit.xhtml">
                      <ui:define name="label">Browse the file</ui:define>
                      <s:fileUpload id="file" accept="application/*" fileName="#{uploadFile.value}"></s:fileUpload>
                  <div style="clear:both"/>
              <div class="actionButtons">
                  <h:commandButton id="uploadFile" value="UploadFile"

      I dont how to pass the file path which i get when browsing the file to my processfile method.
      I just need only the filepath from front-end to action file(UploadFile.java).
      Please help me in correcting my code.


        • 1. Re: how to fetch file path while file uploading
          Umut Fikret  Gürkavcu Newbie

          Why are you need the filepath ? If you need filedata you can get it from s:fileUpload after page was posted.

            <s:fileUpload data="#{uploadFile.fileData}" accept="application/*" fileName="#{uploadFile.value}" />
          public class UploadFile
            private byte[] fileData;

          May be you can need to add these params inside components.xml for limiting max file size that transfered from the user.

          // 1MB
          <component class="org.jboss.seam.web.MultipartFilter">
                      <property name="createTempFiles">true</property>
                      <property name="maxRequestSize">1048576</property>


          • 2. Re: how to fetch file path while file uploading
            vasuki hn Newbie

            Hi Umut,

            Thanks for replying. I need only the file path and the reason is, I need the file path of the browsed file which will be sent as an parameter to the processing method.

            So could you help me in figuring out the solution?


            • 3. Re: how to fetch file path while file uploading
              Umut Fikret  Gürkavcu Newbie

              As far as i know there is no way to get full path of browsed file for security reasons. In most cases people dont need the path of file and i dont imagine where are you using this file path. Are you using s:fileUpload for only to get path of file ? If this is what you aim s:fileUpload is not capable of getting filepath. Its atrributes are :

                    data — this value binding receives the binary file data. The receiving field should be declared as a byte[] or InputStream (required).
                    contentType — this value binding receives the file's content type (optional).
                    fileName — this value binding receives the filename (optional).
                    accept — a comma-separated list of content types to accept, may not be supported by the browser. E.g. "images/png,images/jpg", "images/*".
                    style — The control's style
                    styleClass — The control's style class 

              • 4. Re: how to fetch file path while file uploading
                vasuki hn Newbie

                Ok. Then if we use s:fileupload tag inxhtml file for uploading, how do we get the filename at the backend(.java) when we use the filename attribute of the tag?
                Do we need to have a table in our database to store the filename and later fetch using getter/setter methods or do we get the filename directly?

                Could you explain giving an example?