Friday 4 May 2018

Upload Files into Server in OAF Dynamically


1. Create a New Workspace and Project 

File > New > General > Workspace Configured for Oracle Applications 
File Name – FileUploadDemo
 
Automatically a new OA Project will also be created
 
Project Name -- FileUploadDemo 
Default Package -- xxcustom.oracle.apps.fnd.fileuploaddemo
 
2. Create a New Application Module (AM) 

Right Click on FileUploadDemo > New > ADF Business Components > Application Module 
Name -- FileUploadAM
Package -- xxcustom.oracle.apps.fnd.fileuploaddemo.server 
Check Application Module Class: FileUploadAMImpl Generate JavaFile(s)
 
3. Create a New Page 

Right click on FileUploadDemo > New > Web Tier > OA Components > Page
Name -- XxchrFileUploadPG 
Package -- xxcustom.oracle.apps.fnd.fileuploaddemo.webui

4. Create a New Item messageFileUpload Bean under MainRN 
   
Right click on MainRN > New > messageFileUpload
Set Following Properties for New Item -- 
ID:
MessageFileUpload
Item type:MessageFileUpload 



Write Following Code in XxchrFileUploadCO processFormRequest
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);   

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





Write Following Code in XxchrFileUploadCO  processFormRequest
 
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);   

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

}


public void XxchrupLoadFile(OAPageContext pageContext,OAWebBean webBean)
{ String filePath = "/u01/app/apnac03r12/";
 System.out.println("Default File Path---->"+filePath);

 String fileUrl = null;
 try
 {
  DataObject fileUploadData =  pageContext.getNamedDataObject("MessageFileUpload");

//FileUploading is my MessageFileUpload Bean Id
  if(fileUploadData!=null)
  {
   String uFileName = (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, uFileName); 
   File file = new File("/u01/app/apnac03r12/srini1034", uFileName);
   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);
 }    
}
  


No comments:

Post a Comment