Tuesday, February 9, 2010
Upload Files on UNIX Application Server (OA Framework)
1) Create Project in jdeveloper.
2) Create two business components as
oracle.apps.ak.upload.server and
oracle.apps.ak.upload.webui without any entity,view or application module.
3) in oracle.apps.ak.upload.server create entity object with dual table.
4) create view and application module for the same.
5) in oracle.apps.ak.upload.webui
create one OA page.
6) Also set the form property to TRUE of main region of the type pageLayout.
7) Create one region with messageComponenet Layout
Set AM Defination property.
8) Create one item of type=>messageFileUpload in the messageComponenet Layout region.
9) set prompt,additional text properties of item.
10) create one submit button under the main region.set prompt,additional text,action type=>fire action,event=>uploadFileToServer.
11) under oracle.apps.ak.upload.webui create one controller class.
import following packages in the class.
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.cabo.ui.data.DataObject;
import java.io.FileOutputStream;
import java.io.InputStream;
import oracle.jbo.domain.BlobDomain;
import java.io.File;
12 ) create one method as below in controller class :
public void fileupload(OAPageContext pageContext, String fileuploadBeanId,String server_dir_path)
{
System.out.println("kamlesh");
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();
}
}
}
}
13) In process form request write as below
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
--- your coding as below in PFR process form request-----
fileupload(pageContext,"item1","/cmload");
}
14) Rebuild your .jpr and run the page.
15) If giving error or warning paste below in Impl.java file of Entity.
public void setCreatedBy(Number number)
{
}
public void setCreationDate(Date date)
{
}
public void setLastUpdatedBy(Number number)
{
}
public void setLastUpdateDate(Date date)
{
}
public void setLastUpdateLogin(Number number)
{
}
Controller Class will be like :-
package oracle.apps.ak.upload.webui.webui;
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.cabo.ui.data.DataObject;
import java.io.FileOutputStream;
import java.io.InputStream;
import oracle.jbo.domain.BlobDomain;
import java.io.File;
/**
* Controller for ...
*/
public class MyCO extends OAControllerImpl
{
public static final String RCS_ID="$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
}
public void fileupload(OAPageContext pageContext, String fileuploadBeanId,String server_dir_path)
{
System.out.println("kamlesh");
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();
}
}
}
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
fileupload(pageContext,"item1","/cmload");
fileupload(pageContext,"item3","/cmload");
fileupload(pageContext,"item4","/cmload");
fileupload(pageContext,"item5","/cmload");
fileupload(pageContext,"item6","/cmload");
fileupload(pageContext,"item7","/cmload");
fileupload(pageContext,"item8","/cmload");
fileupload(pageContext,"item9","/cmload");
fileupload(pageContext,"item10","/cmload");
fileupload(pageContext,"item11","/cmload");
fileupload(pageContext,"item12","/cmload");
fileupload(pageContext,"item13","/cmload");
}
}
Kindly note that if your requirement is uploading files on Database server instead of Application Server then you have to create one NFS MOUNT POINT for that in Unix server. While testing this page you can give here the path of your local machine unless it won’t work because here the path given is the server path.
Subscribe to:
Post Comments (Atom)
Kamlesh - thanks for posting this upload page. I was able to create the page and I think I was able to load a file but I'm unsure where it is saved. Do you have an idea where the file is going to be saved on the server?
ReplyDeleteAlso, After I posted the code to the Entity Object java file I was getting an error. I had to use instead:
public void setLastUpdateLogin( oracle.jbo.domain.Number n ) {}
public void setLastUpdatedBy( oracle.jbo.domain.Number n ) {}
public void setLastUpdateDate( oracle.jbo.domain.Date n ) {}
public void setCreationDate( oracle.jbo.domain.Date n ) {}
public void setCreatedBy( oracle.jbo.domain.Number n ) {}
I suppose I could have loaded the package instead. I'm not the best with Java yet.
Anyway, if you can give me an idea to find the proper location where the file was located that would be appreciated!
Thank you,
Tom
I guess I posted to soon! It worked. I changed:
ReplyDeletefileupload(pageContext,"item1","/cmload");
to
fileupload(pageContext,"upload","/TEMP");
to reflect the name of the item (I changed it from item1 to upload) and to save it to my c drive TEMP folder. The file from my desktop was saved to my TEMP folder. Very cool. I guess I need to figure out how to load on the eBusiness Suite next. Thank you for the help.
Tom
Hi Kamlesh,
ReplyDeleteFirst, thanks for sharing the process. I have two questions. 1. The systax for file upload is: fileupload(pageContext,"upload","/TEMP"); If I want the file to be moved to a particular top, how do I do it, for e.g. can I give "$XX_TOP/temp" ?
2. Looks like the file is uploaded in BIN mode, how do i transfer the file in ascii mode?
Thanks,
can you please send me the code that are working. i tried but its not working it always getting DataObject is null. pls send the code to venkat.planka@gmail.com
ReplyDeleteThanks in advance.
can you please provide me all the steps in detail ? I am new to OA Framework.
ReplyDeletePlease mail me steps at ashish.jaroli@gmail.com
Hi Kamalesh,
ReplyDeleteI want to upload the file Database Server. But i didnt understand the NFS mount point.
can you please elaborate the same. And can you provide the code for the same if possible.
Hi Kamlesh,
ReplyDeleteMy question:
Is this possible to implement this in an advanced table ?
Requirement is that we have an advanced table in which each row has an file upload facility.
We had followed your code but this is not working in case of advanced table.
Thanks in advance.
Sachin