Saturday, October 6, 2012

OAF Upload Blob File in Table Column

 OAF Upload Blob Table Column

1)Create OA Page.
2)Add AM Defn to pageLayoutRN.
3)Create StackRegion or any required base layout region. (optional)
4)Add form Region with columns as



5)Change Attached File         a)Remove View instance and View Attribute b)  Data type to BLOB.


6)Create controller  on PageLayout RN.

7)Inside AMimpl   add below code
**********************************************************
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;

import oracle.jbo.Transaction;

      public void createAttach()
      {
        OAViewObject vo = (OAViewObject)getXxFileBlobsVO1();
        // Per the coding standards, this is the proper way to initialize a   
        // VO that is used for both inserts and queries.  See View Objects   
        // in Detail in the Developer's Guide for additional information.       
        if (!vo.isPreparedForExecution())    
        {      
            vo.executeQuery();    
        }
        Row row = vo.createRow();   
        vo.insertRow(row);
       // Required per OA Framework Model Coding Standard M69
       row.setNewRowState(Row.STATUS_INITIALIZED);
      } // end createAttach() 

public void apply()
{
  getTransaction().commit();
} // end apply()
**********************************************************


8)In Controller processRequest add below code
**********************************************************
import oracle.apps.fnd.framework.OAApplicationModule;
..
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      am.invokeMethod("createAttach", null);
**********************************************************


9)Add createBlobDomain  method inside Controller.
**********************************************************
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.domain.BlobDomain;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.sql.SQLException;
..
 private BlobDomain createBlobDomain(DataObject pfileUploadData)
{
    // init the internal variables
        InputStream in = null;
        BlobDomain blobDomain = null;
        OutputStream out = null;
       
    try
    {
        String pFileName =
        (String) pfileUploadData.selectValue(null,"UPLOAD_FILE_NAME");
        BlobDomain uploadedByteStream = (BlobDomain)pfileUploadData.selectValue(null,pFileName);
        // Get the input stream representing the data from the client
        in = uploadedByteStream.getInputStream();
        // create the BlobDomain datatype to store the data in the db
        blobDomain = new BlobDomain();
        // get the outputStream for hte BlobDomain
        out = blobDomain.getBinaryOutputStream();
        byte buffer[] = new byte[8192];
            for(int bytesRead = 0; (bytesRead = in.read(buffer, 0, 8192)) != -1;)
                out.write(buffer, 0, bytesRead);
            in.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (SQLException e)
    {
        e.fillInStackTrace();
    }
    // return the filled BlobDomain
    return blobDomain;
}
**********************************************************


10)Add below piece of code inside processForm Request
**********************************************************
import oracle.apps.fnd.framework.OAViewObject;
import oracle.jbo.Row;
..
// Select file then hit commit
          if (pageContext.getParameter("CommitBtn") != null)
            {
           
                OAViewObject vo = (OAViewObject)am.findViewObject("XxFileBlobsVO1");
                oracle.jbo.domain.Number fileId = (oracle.jbo.domain.Number)vo.getCurrentRow().getAttribute("FileId");
                Row row = (Row)vo.getCurrentRow();
               
                DataObject fileUploadData =
                                (DataObject)pageContext.getNamedDataObject("AttachedFile");
                               
                               
                if(fileUploadData != null)
                    {
                      String uFileName =
                      fileId.toString()+"_"+(String) fileUploadData.selectValue(null,"UPLOAD_FILE_NAME");
                      String contentType =
                      (String)fileUploadData.selectValue(null,"UPLOAD_FILE_MIME_TYPE");
                      row.setAttribute("AttachedFile", createBlobDomain(fileUploadData));
                      row.setAttribute("AttachedFileName", uFileName);
                      row.setAttribute("Contenttype", contentType);
                    } 
                    // File Upload Ends
      
            am.invokeMethod("apply"); 
                String fileName = (String)vo.getCurrentRow().getAttribute("AttachedFileName");
                OAException confirmMessage = new OAException("File "+fileName+" uploaded succesfully .",OAException.CONFIRMATION);              
            pageContext.putDialogMessage(confirmMessage);                   
}
**********************************************************






Note:
You can set the profile option called UPLOAD_FILE_SIZE_LIMIT to specify the maximum size of the file
a user can upload. For example, if you set UPLOAD_FILE_SIZE_LIMIT to 500K, then during the http POST
request, OA Framework reads only up to 500K from the stream and throws an exception if the uploaded file is
larger than 500K.


To Upload File into Standard FND_LOBS  table
http://robertjungerius.wordpress.com/2011/04/08/building-a-generic-upload-page-in-oa-framework/



For

OAF Page to Upload Files into Server from local Machine

https://blogs.oracle.com/prajkumar/entry/oaf_page_to_upload_files
http://mukx.blogspot.com/2010/01/upload-file-to-application-server-using.html
http://mystuffoaf.blogspot.com/2012/03/uploading-file-into-server-from-local.html?zx=61db5b806994d831


3 comments:

  1. I think this data is insufficient.... Coz.. EO, and VO definitions are not seen.. SO Im doubt full if its going to works ....

    ReplyDelete
  2. I think this data is insufficient.... Coz.. EO, and VO definitions are not seen.. SO Im doubt full if its going to works ....

    ReplyDelete
  3. Hi,

    I have same requirement. 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