Skip to Main Content

Simple way to display pictures stored outside Oracle XE in an html region

Here is how you can show images from server folder: This is just example and assume you create new app. I also assume your XE database is in windows machine. Connect to SQL plus as SYS and create directory:

create directory my_img_dir as 'c:\my_images\';

Grant read privilege on directory to DAD user (ANONYMOUS):

grant read on directory my_img_dir to anonymous;

Grant read privilege on directory to your application parsing schema. Change "my_schema" to your own schema:

grant read on directory my_img_dir to my_schema;

Create new app and 2 blank pages. I assume first page (id 1) is where you show images. Second page (id 2) is just for call application process. Create application process point "On Load:Before Header"

DECLARE
  l_lob     BFILE;
  l_length  NUMBER;
BEGIN
--
  l_lob :=  BFILENAME('MY_IMG_DIR', :REQUEST);
  l_length := DBMS_LOB.getlength(l_lob);
  --
  htp.flush;
  htp.init;
  --
  htp.p('Content-length: ' || l_length);
  --
  htp.p('Content-Disposition: inline; filename="&REQUEST."');
  --
  -- close the headers
  owa_util.http_header_close;
  --
  -- download the BLOB
  wpg_docload.download_file(l_lob);
--
END;

Make process conditional if page is 2. Create HTML region to page 1 and place to region source:

<img src="f?p=&APP_ID.:2:&APP_SESSION.:my_picture.gif" alt="" />

Replace "my_picture.gif" with real image name you have in folder c:\my_images. Image name is case sensitive PS: In above instructions replace c:\my_images\ with e.g. /var/my_images in Linux. Make sure "others" have read permission to folder and image files in it. Folder owner and group can be e.g. root.

Original article in Oracle APEX forum.

Comments

  • Mathias Maciel 4 May 2020

    Great!

    Is there any tutorial do you recommend for? I mean to configure a web server for images.

  • Jari Laine 4 May 2020

    My advices. Optimize your application as I can't figure any reason to show 1200 images in one page at once. Don't serve images from through database, use web server.

  • Mathias Maciel 4 May 2020

    You’re right!

    That’s why I’m asking for best solution. I want to display images on Interactive Report but optimizing the server and avoiding to overload it.

    By this way I’ll apply call to this process for each page for one registry like a profile page and there is where image will show (for now I got 500 Server Error).

  • Jari Laine 4 May 2020

    Do you mean that when user opens APEX page, there is 1200 images? If so, as I understand using this solution you open 1201 sessions to database for single user. What if there is 100 users at same time viewing your page?

  • Mathias Maciel 3 May 2020

    I’ve 1200 registries to display (for now). Changing the position of LOB close syntax with only one registry I got 500 Server Error (different error) but by calling process for each row server collapses and APEX freezes up.

  • Jari Laine 2 May 2020

    I just tested with original page process to display 60 pictures in single page. There wasn't any issue. I have not made any changes to session_max_open_files parameter.

    SQL> show parameter session_max_open_files;
    NAME                   TYPE    VALUE
    ---------------------- ------- -----
    session_max_open_files integer 10
    
  • Mathias Maciel 2 May 2020

    Even if it's obvious I use XE database and images are crucial.

    As you already know store to database isn't an option for now. This application will manage sensitive images data to host them anywhere.

    I'll appreciate your help if you guide me to solve this by the best way!

  • Jari Laine 2 May 2020

    I just wonder why you need this. Why you don't store images to database or use web server to share images?

  • Mathias Maciel 2 May 2020

    It's still not working I got same error.

    I found Oracle article: https://docs.oracle.com/cd/B19306_01/appdev.102/b14249/adlob_managing.htm#sthref126

    By that way it will not possible to replicate this on Interactive Report assuming that the session_max_open_files parameter is by default 10 even if we alter this I could impact negatively on the server.

  • Jari Laine 2 May 2020

    Try add call to dbms_lob.close. Here is modified code for process. See if it helps.

    DECLARE
      l_lob     BFILE;
      l_length  NUMBER;
    BEGIN
    --
      l_lob :=  BFILENAME('MY_IMG_DIR', :REQUEST);
      dbms_lob.close(l_lob);
      l_length := DBMS_LOB.getlength(l_lob);
      --
      htp.flush;
      htp.init;
      --
      htp.p('Content-length: ' || l_length);
      --
      htp.p('Content-Disposition: inline; filename="&REQUEST."');
      --
      -- close the headers
      owa_util.http_header_close;
      --
      -- download the BLOB
      wpg_docload.download_file(l_lob);
    --
    END;