Sunday, January 5, 2014

Uploading File to server from OAF Page

Uploading Flat File to server from OAF Page


Now we are going to learn about how to load the flat files to server from oaf page.
For uploading the files in OAF we have the item called “MessageFileUpload” using this we can load the files.

Steps are as follows.

Step1: - Create the workspace and project.

Step2: - Create the application module.

Step3: - Create the page and attach the application module to the page and in properties
              Give the window title and title.

Step4:- Create one region with style “message component layout” under page layout region
And create two items under message component layout one with style “messageFileUpload”        and second is a submit button.

The structure of the page is like below.



If u want any spaces between the items then create the item with style spacer.




Step5: - Create the controller for pageLayoutRegion.

            Write the following code in the processFormRequest method of a controller
             
             import oracle.cabo.ui.data.DataObject; 
             import java.io.FileOutputStream; 
             import java.io.InputStream; 
             import oracle.jbo.domain.BlobDomain; 
             import java.io.File; 
             import oracle.apps.fnd.framework.OAException; 

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{ super.processFormRequest(pageContext, webBean);  

    TFitFileLoaderAMImpl am = TFitFileLoaderAMImpl)pageContext.getRootApplicationModule();

if(pageContext.getParameter("Submit")!=null)
            {
                  am.uploadFile(pageContext,webBean);    
             }
 }

           Create a method called uploadFile in AMImpl.java

          Otherwise you can create the method in controller only.
          If you create method in controller then in the above code do not initialize Application module and                   while calling the method use the bellow syntax.
          uploadFile(pageContext,webBean);

  


        import java.io.File;
        import java.io.FileOutputStream;
        import java.io.InputStream;
        import java.sql.Types;
        import oracle.apps.fnd.framework.OAException;
        import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
        import oracle.apps.fnd.framework.server.OADBTransaction;
        import oracle.apps.fnd.framework.server.OADBTransactionImpl;
        import oracle.apps.fnd.framework.webui.OAPageContext;
        import oracle.apps.fnd.framework.webui.beans.OAWebBean;
        import oracle.cabo.ui.data.DataObject;
        import oracle.jbo.domain.BlobDomain;
        import oracle.jdbc.OracleCallableStatement;

         public void uploadFile (OAPageContext pageContext,OAWebBean webBean)
        {
 String filePath = “/Software/apps/apps_st/appl/xx/msd/tfit/”;
  
 String fileUrl = null;
            
try
            {
           
  DataObject fileUploadData =  pageContext.getNamedDataObject("Give the id of message file                                                                                                                            upload item");

                  if(fileUploadData!=null)
                  {
                    String FileName = (String)fileUploadData.selectValue(null, 
"UPLOAD_FILE_NAME");   
             String contentType = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");   
                    FileOutputStream output = null;
                    InputStream input = null;
BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, FileName); 
                              
          File file = new File(“/Software/apps/apps_st/appl/xx/msd/tfit”, FileName);  
          output = new FileOutputStream(file);
                       input = uploadedByteStream.getInputStream();
                       byte abyte0[] = new byte[0x19000];
                      
                       int i;
    
                      while((i = input.read(abyte0)) > 0)
                      output.write(abyte0, 0, i);
                      output.close();
                      input.close();
                    }
            }
            catch(Exception ex)
            {
                        throw new OAException(ex.getMessage(), OAException.ERROR);
            }    
        }

Step6: - Register the page in server and run the page.

            
     


            

         Brows the file and click on submit button it will store in server.



           




12 comments:

  1. How can I read $CUSTOM_TOP value dynamically in JAVA ? So that I dont need to hard code the path.

    ReplyDelete
    Replies
    1. You can create a profile option for the path and in coding get the value from profile.
      In profile you can set which ever the path you want.

      String filePath= pageContext.getProfile("XX_FILE_UPLOAD_DIR_PATH");


      Delete
  2. Hi,
    can we upload the file to multiple application servers, we have two application servers and one data base , how can we mention the application server details in java code

    Thanks
    Regards
    kishore

    ReplyDelete
    Replies
    1. Did you resolve this problem? I am facing the same.

      Delete
  3. Very good post, can you select multiple files and upload or always one file at a time?

    Thanks,
    Justin

    ReplyDelete
    Replies
    1. One file at a time, you can not select multiple files.

      Delete
  4. Hi,

    I have an advanced table, where rows are added clicking on "Add rows" button and files are uploaded, I am not able to catch file names except the last one when I click on Submit,Pls help.

    ReplyDelete
  5. Hi,

    How can we give the permissions 777 through this process.

    Regards,
    Chanakya

    ReplyDelete
    Replies
    1. Use below code

      Runtime.getRuntime().exec((new StringBuilder()).append("chmod 777 "+targetFile).toString());

      Delete
  6. Hi,
    Do you know is there is a way to make the upload file allows selecting multiple files at the same time?

    Thanks in advance,
    Romina

    ReplyDelete
  7. WE can download the file server by OAF page

    ReplyDelete
  8. We can download the file from server by OAF page

    ReplyDelete