Thursday 8 March 2012

OAF(File upload to application server)

Following is the code which u have to written in Controller class
steps to follow 
1) create one item on page as  type messagefileupload
2)and call the method  from any event
uploadFileToServer(pageContext,"item2","/u03/DEV/devcomn/java");
3) and simply make changes as change the item2  and the path that is highlighted
(you can check it by changing the path to local system as "D:/new folder/") this is for testing 

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import java.io.Serializable;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.OAException;
import oracle.cabo.ui.data.DataObject;
import java.io.FileOutputStream;
import java.io.InputStream;
import oracle.jbo.domain.BlobDomain;
import java.io.File;

in process form request write under  event
{
 uploadFileToServer(pageContext,"item2","/u03/DEV/devcomn/java");
}

public void uploadFileToServer(OAPageContext pageContext,
String fileuploadBeanId,
String server_dir_path)
{
DataObject fileUploadData =
(DataObject) pageContext.getNamedDataObject(fileuploadBeanId);
if(fileUploadData!=null)
{
String uFileName =
(String) fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
String contentType =
(String) fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");

File file = new File(server_dir_path, uFileName);
FileOutputStream output = null;
InputStream input = null;
try
{
output = new FileOutputStream(file);
BlobDomain uploadedByteStream =
(BlobDomain) fileUploadData.selectValue(null, uFileName);
input = uploadedByteStream.getInputStream();
for (int bytes = 0; bytes < uploadedByteStream.getLength(); bytes++)
{
output.write(input.read());
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (input != null)
{
input.close();
}
if (output != null)
{
output.close();
output.flush();
}
}
catch (Exception ez)
{
ez.printStackTrace();
}
}

}
}

steps to remember
-1)always check the item id of messagefileupload item  and change at highlighted  item2 place
2)sometimes the u are unable to store the file at application server because u dont have full access to create or write any thing on server so check with DBA and told him give the full access rights to the folder.


10 comments:

  1. Nice Post... One question
    to upload file at
    /u03/DEV/devcomn/java we must deploy code to Unix server right . If we are running from JDevloper then we can only upload to D:/new folder/.
    Appreciate your response.

    ReplyDelete
  2. Hi,

    BlobDomain uploadedByteStream =
    (BlobDomain) fileUploadData.selectValue(null, uFileName); is giving me null .. file name and content type are returned fine .. please help

    ReplyDelete
  3. I need to upload multiple file on unix server from a local machine. number of files not fixed. please help me.

    ReplyDelete
    Replies
    1. HI Brajesh,

      Did you achieve multiple files upload, please let me know

      Delete
  4. Will the uploaded file be stored in CM, DB or application server?

    ReplyDelete
    Replies
    1. Thanks Brajesh for the reply. Is there any standard code available that will move the file to CM server?

      Delete
    2. Hi Brajesh,

      Were you able to upload multiple file from a single OA Page let's say advanced table region?

      Please let me know how you achieve this.

      Thanks a lot.

      Delete
  5. 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