ADF – while downloading attachment

Take a File Upload scenario in ADF. The requirement is the user should be able to upload a file using browse button. once the user selects a file, the file should appear as link so that user can click on it and view. finally it can be saved to database using an apply button. In the database, this file will be stored in a field of type ORDSYS.ORDDOC.
In the above scenario, to download the file , I got the inputStream from the VO attribute which is of type OrdDocDomain and manipulated it to show it on page.
Now the code I used to get the inputStream from OrdDocDomain variable called file is:

in = file.getDataInStream();
Now the issue:
Once the data is saved to database, if I try to download the file, its working perfectly.
But before clicking Apply, if I try to download the file by clicking on the link, I am getting

The reason for the above exception is getDataInStream() method of OrdDocDomain gets the inputStream only if the data is already committed to database. it cannot fetch it if the data is still in VO/EO cache (i.e before commit).

So the code used to solve the above issue is :

//If the file is connected to database (already existing in db) then get the data in stream
in = file.getDataInStream();
//if the file is just uploaded and so not posted to db yet, get the temporarily stored content source
{ OrdByteArraySource bs = (OrdByteArraySource)file.getContentSource();
in = bs.getInputStream();

And now everything is working perfectly as expected.

This entry was posted in ADF. Bookmark the permalink.

4 Responses to ADF – while downloading attachment

  1. Hi,

    Do you have sample code for using OrdDocDomain? I am struggling with an upload/download scenario using OrdDocDomain. I posted on the Oracle forums just moments ago:

    Your help would be greatly appreciated.

    • Sowjanya Bhupathiraju says:

      sorry Bijesh! took a break and so did not check your post till now. please let me know if you found the solution or u still need the sample code.

  2. Bijesh says:

    The sample code would be great. Thanks!

    • Sowjanya Bhupathiraju says:

      following is a code to convert a UploadedFile type (in ADF) to ordDocDomain type. (you can refer this code to know how to convert byte array to ordDocDomain)
      public OrdDocDomain convertToOrdDocDomain(UploadedFile file) {
      OrdDocDomain ordDoc = null;
      try {
      //create new byte array and get the inputstream of uploaded file
      byte[] b = new byte[(int)file.getLength()];
      DataInputStream in =
      new DataInputStream(file.getInputStream());

      int byteRead = 0;
      int totalBytesRead = 0;
      //this loop converts the uploaded file into byte code
      while (totalBytesRead < file.getLength()) {
      System.out.println("reading bytes");
      byteRead =, totalBytesRead, (int)file.getLength());
      totalBytesRead += byteRead;
      //create new OrdDocDomain object from the byte array
      ordDoc = new OrdDocDomain(b);
      ordDoc.setSource(file.getContentType(), null,
      //update the vo attribute with the attached doc

      } catch (SQLException _sqle) {
      catch(IOException _ioe) {

      you can set this ordDocDomain to a vo row just like any other datatype attributes. (OAF/ADF)

      OrdDocDomain ordDoc = convertToOrdDocDomain(uploadedFile);
      row[0].setAttribute("Document", ordDoc);
      let me know if you have any questions in the above code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s