Monday, August 30, 2010

Uploading and Downloading Images in Oracle ADF

Hi,

In this post we will see how to upload and download images in Oracle ADF application.

Note: this example does not store images in BLOB column it just copy the image from client machine to server directory.

Download the sample workspace





Happy JDeveloping,
Zeeshan Baig

41 comments:

  1. What about reading and writing images to blob and showing it on page like in this app?

    ReplyDelete
  2. Hi Boris,

    This will be coming soon.

    ReplyDelete
  3. Hi,

    Reading and writing images from Blob http://baigsorcl.blogspot.com/2010/09/store-images-in-blob-in-oracle-adf.html

    ReplyDelete
  4. Hi Baig
    Thanks for your clear demonstration. I have a question, I have my weblogic running as standalone server and I don't use Jdeveloper to run my application. I can upload the images and they successfully upload to a folder(As I can see them at the time I uploaded in the folder); however, I should restart my server in order to see them in my web application!. I'm not sure what the problem is, and it seems weird. do you know where I have done wrong?
    cheers

    ReplyDelete
  5. @khash.

    I am not sure what is the issue make sure the you have set the partial submit to true and partial triggers on image component.

    ReplyDelete
  6. Hi,

    I am working on an application, where the user can upload their pic and that pic will be downloaded to blob column of the table. Before it add to the column i want this pic to be displayed as soon as the user upload this. What should i mention at af:image source property? I am actually giving expression of a outputstream variable from a bean but this not helping. Any suggestions?

    ReplyDelete
  7. Check this entry http://baigsorcl.blogspot.com/2010/09/store-images-in-blob-in-oracle-adf.html

    doing the same thing as you want.

    ReplyDelete
  8. hi ....the image is not stored in the server location ....but it is alerady displaed in the image componant ....i dont know how this happen ?...

    ReplyDelete
  9. Hi Tokando,

    The file saves in your integrated server directory. i have explained in the video

    ReplyDelete
  10. okay Zeeshan it is saved but if you try to run the application again the saved files is automatically deleted .
    iam using jdeveloper r2....

    ReplyDelete
  11. Thank you!! This video had been very usefull for me!! but while i tried the same in jsff i am getting error as NullPointerException in

    private BlobDomain createBlobDomain(UploadedFile file) {

    InputStream in = null;
    BlobDomain blobDomain = null;
    OutputStream out = null;

    try {
    in = file.getInputStream(); //Null Pointer Exception

    ReplyDelete
  12. This vido is very help full for me but Please tell some thing about storing and streaming video using adf

    ReplyDelete
  13. Hi Naeem the process should be similar. You can store videos in BLOB column.

    Use af:media to play video files instead of af:image check this link http://www.baigzeeshan.com/2010/11/how-to-display-videos-in-adf-fusion.html

    ZB

    ReplyDelete
  14. hi Zeeshan your post work at integrated weblogic ..but i tried it after deploy my application in standalone weblogic server ..the image not displayed ...can you tell me what is wrong ....

    ReplyDelete
  15. Hi Tokando,

    Sorry for late response being busy for last few weeks...anyways

    Which path are you using in your code? can you share any example.

    ZB

    ReplyDelete
  16. Hi Zeeshan,

    I am having a problem with the "Employeeid" attribute binding.
    The getCurrentEmployeeId() method is always giving me the employee id of the 1st employee...

    Can you give a hint about what the problem might be ?

    Thanks in Advance.

    ReplyDelete
  17. Hi Neo,

    What code are you using to retrieve Id? try using reading from Iterator like
    DCIteratorBinding iterBind= (DCIteratorBinding)dcBindings.get("testIterator");
    String attribute = (String)iterBind.getCurrentRow().getAttribute("field1");

    Check this page for more handy code http://biemond.blogspot.com/2009/03/some-handy-code-for-backing-beans-adf.html

    Hope it help,
    ZB

    ReplyDelete
  18. For this we have to create Data Source in weblogic connsol???

    ReplyDelete
    Replies
    1. Hi,

      Not only for this if you application uses database then in order to work it you have to create data source in weblogic server (unless you are connecting differently)

      ZB

      Delete
  19. Hi Baig,
    Thanks for the turorial.
    I can copy uploaded image files to a server locations now.
    But how to copy if the uploaded file is MS words doc or PDF.
    Could you please provide the code?

    Regards,
    Sam

    ReplyDelete
    Replies
    1. Hi,

      Can you explain your use case in detail. What do you mean by Copy ?

      If you want to download a file then the use case is covered in the video.

      Zeeshan

      Delete
    2. Hi Zeeshan,

      My requirement is to enable user upload MS Office/pdf files (instead of image files) to a specific location in Weblogic server.
      From your code I understood how to do the same for image files. But I want the code for MS words/pdf files.

      Regards,
      Sam

      Delete
    3. You can follow same steps for WORD and PDF files as well.

      It depends on client how to open not for server.

      ZB

      Delete
  20. how can i upload and download files using oracle forms

    ReplyDelete
    Replies
    1. Check this http://www.baigzeeshan.com/2010/02/storing-and-retrieving-images-word.html

      ZB

      Delete
  21. Hi,

    I downloaded your application and try to run.

    GOT THIS error


    <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg=JBO-33001: Configuration file /demo/model/services/common/bc4j.xcfg is not found in the classpath.

    ReplyDelete
  22. Hi ,
    Thanks for the tutorial.
    When i m uploading image, it uploaded successfully but when i m updating image with existing image it doesn't refresh.
    For refreshing we have to call reload method of browser.
    Is there another way of doing this as i don't want to call reload.

    ReplyDelete
    Replies
    1. Hi,

      you can refresh the Image component only by using partial triggers.

      Try it

      ZB

      Delete
  23. Hi Zeeshan Baig,

    I am trying to display images from file system. And, since my application will have to update the images frequently, I am thinking of deploying images in a jar file to WLS console (Shared Library Resource). In this way, when I am updating any image file, I can just re-deploy the images jar file only. Do you have any suggestions as to how this can be implemented? Or is there any other way? Thanks.

    ReplyDelete
    Replies
    1. Hi,

      Sorry for late response. Yes you can do it check this blog http://www.oracle.com/technetwork/developer-tools/adf/learnmore/86-images-from-jar-427953.pdf

      Delete
  24. thanks for your share.
    I have downloaded the simple file(HrImageExample.zip). but the sample can't run because the datacontorl(HrAppModuleDataControl) don't exsit in the model.
    Could you please check the simple?

    ReplyDelete
    Replies
    1. Hi,

      Check your database connection from Jdeveloper. Click the refresh icon in data control palette to verify.

      Zeeshan

      Delete
  25. Hi Zeeshan,
    The code is working perfectly except for a small thing, when a picture is uploaded, it is saved in the /images folder under the Integrated weblogic, while the /images folder in the project itself remains empty, as a result the picture is not displayed when running the application....please advice...thanks

    ReplyDelete
    Replies
    1. Hi,

      You need to setup web directory on server to store images and configure your application to use that directory using relative path. for example /images/myImage.jpg Google you will find some solutions

      Hope it helps

      Delete
  26. Dear Zeeshan,

    I am getting following error.

    DF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6>
    oracle.jbo.ConfigException: JBO-33001: Configuration file /demo/model/services/common/bc4j.xcfg is not found in the classpath.

    I am using following JDEV version
    Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S

    Can you please help me to fix this

    Sandip Wavhal

    ReplyDelete
    Replies
    1. Hi,

      Check this might help https://mjabr.wordpress.com/2012/11/27/how-to-solve-oracle-jbo-configexception-jbo-33001/

      Zeeshan

      Delete
  27. Dear Zeeshan
    I can't download file. The link is died

    ReplyDelete
  28. Thank Zeeshan
    I mean an you reupload source code?
    I'm building Upload image aplication but error

    Thank for your help!
    Lang Thang

    java.io.FileNotFoundException: (No such file or directory)
    java.lang.NullPointerException
    at ncs.hcm.view.ImageUploadBean.getCurrentEmpId(ImageUploadBean.java:64)
    at ncs.hcm.view.ImageUploadBean.uploadImage(ImageUploadBean.java:100)
    at ncs.hcm.view.ImageUploadBean.uploadImageFileAction(ImageUploadBean.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1988)
    ...more

    <_logUnhandledException>
    javax.faces.el.EvaluationException: java.lang.NullPointerException
    at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:58)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1988)
    at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:183)
    at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
    at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
    ...more
    Caused by: java.lang.NullPointerException
    at ncs.hcm.view.ImageUploadBean.uploadImage(ImageUploadBean.java:117)
    at ncs.hcm.view.ImageUploadBean.uploadImageFileAction(ImageUploadBean.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
    ... 68 more

    javax.servlet.ServletException
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:663)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
    ...more
    Caused by: java.lang.NullPointerException
    at ncs.hcm.view.ImageUploadBean.uploadImage(ImageUploadBean.java:117)
    at ncs.hcm.view.ImageUploadBean.uploadImageFileAction(ImageUploadBean.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    ... more

    ReplyDelete
    Replies
    1. It clearly says java.io.FileNotFoundException: (No such file or directory)

      Delete