Single Article

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

Category APEX Tricks

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

  • Amit 23-NOV-19

    This is giving me errors

    is_internal_error: false

    ora_sqlcode: -6502

    ora_sqlerrm: ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275

    component.type: APEX_APPLICATION_PROCESSES

    component.id: 8425995037776750

    component.name: ShowImages

    error_backtrace:

    ORA-06512: at "SYS.WPG_DOCLOAD", line 89

    ORA-06512: at line 20

    ORA-06512: at "SYS.DBMS_SYS_SQL", line 2107

    ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_190200", line 601

    ORA-06512: at "APEX_190200.WWV_FLOW_DYNAMIC_EXEC", line 2550

    ORA-06512: at "APEX_190200.WWV_FLOW_PROCESS_NATIVE", line 96

    ORA-06512: at "APEX_190200.WWV_FLOW_PROCESS_NATIVE", line 1156

    ORA-06512: at "APEX_190200.WWV_FLOW_PLUGIN", line 2585

    ORA-06512: at "APEX_190200.WWV_FLOW_PROCESS", line 203

    error_statement:

    begin 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: filename=""');

    --

    -- close the headers

    owa_util.http_header_close;

    --

    -- download the BLOB

    wpg_docload.download_file(l_lob);

    --

    END;

    end;

        
  • Md.Kawsar Uddin Forhad 15-NOV-19

    Hi Jari's, Can I Call a image in Oracle Apex Reports like (Classic, Interactive) from outside of oracle database using oracle function. My database version is 11g.

    Thank u.

        
  • Jari Laine 01-DEC-18

    Hi Masud,

    This blog use standard APEX features. There isn't anything special to generate URL. See APEX documentation.

    Regards,
    Jari

        
  • Masud 30-NOV-18

    How i make a system that dynamically change URL

    like this blog

    Home: https://jaris.tilaa.cloud/apex/f?p=BLOG:HOME:::NO:::

    Files: https://jaris.tilaa.cloud/apex/f?p=BLOG:FILES:::NO:::

    Author: https://jaris.tilaa.cloud/apex/f?p=BLOG:AUTHORS:::NO:::

    tell me please

        
  • Jari Laine 09-NOV-17

    Hi Md. Masud Rana,

    I haven't check how use bfile from remote directory.
    Try check Oracle documentation.

    Regards,
    Jari

        
  • Masud 08-NOV-17

    Hi Jari

    Very good Post. How can i retrieve image or directory

    which is located shear drive from another pc like

    (create directory drug_image_dir as '\\192.100.0.05\smb\image';)

    * When run (user_name/Password) need Application

    how & where i place (user_name/Password) in process?

    ORA-22288: file or LOB operation GETLENGTH failed The specified network password is not correct.

    Thanks a lot

    Regards,

    Masud

        
  • Jari Laine 08-MAY-12
  • jabbar 08-MAY-12
    Hi, I have some question about your post, 1. i have some files (.jpg,.pdf,.docx) stored in local folder which filename specified in the table. I want to open a file by clicking the record (example filename) of either interactive or classic report in APEX. Can you help with your coding. //l_lob := BFILENAME('IMAGES', :REQUEST); here what it means :REQUEST is a column or what? thanks Abdul Jabbar     
  • Jari Laine 06-OCT-11

    Hi,

    You just output needed HTML before/after image.
    Maybe you PL/SQL dynamic content region.

    Regards,
    Jari

        
  • mrosa 06-OCT-11
    Very good article. How can I add some text before/after the picture? I need to build a student cart , with name , period and the photo. thanks.     

Global Right Column

Search

Archives

Subscribe in a Reader