Displaying Images in Oracle Apex

Displaying Images in Oracle Apex


Steps :

1. Create PL/SQL dynamic Content Region and write the code

declare
 cursor c1 is 
 select FILE_SHORT_INFO,emp_code from prtl_files where emp_code = :P8_empcd;
 t varchar2(200);
begin
   for i in c1
   loop
    htp.p('<body>');htp.p('<p>&nbsp;</p>');   
    htp.p('<table width="100%">');    
    htp.p('<tr>');
 
    for rec in (select * from PRTL_FILES
            where emp_code = :P8_EMPCD and status='A')
    loop
      IF rec.ATT_MIMETYPE is not null or rec.ATT_MIMETYPE != '' THEN 
htp.p('<td colspan="2">'); htp.p( '<img src="my_image_display?                    fid='||NVL(rec.FILE_ID,0)||'" height="'||100||'"/>' );
                         htp.p('</td>');          
      else
        htp.p('<td colspan="2">');    htp.p( 'No Image ');
                          htp.p('</td>');
     END IF;
    end loop;
  
    begin
       select pos_owner ||' ['||pos_name||']' into t from prtl_pos
       where emp_code = :P8_empcd;
    exception
       when no_data_found then t:='N/A';
    end;
    htp.p('<br>');
    htp.p('<b>'); htp.p(t); htp.p('</b>');
htp.p('</tr>');
htp.p('<tr>');
htp.p('<td colspan="2">'); htp.p(i.FILE_SHORT_INFO);
        htp.p('<p>&nbsp;</p>');
htp.p('<p>&nbsp;</td>');
htp.p('</tr>');
htp.p('</table>');
    htp.p('</body>');
    htp.p('</html>');
end loop;
end;

Note : I wrote this code as per my requirement. You need to change the code as per your requirement.

2. My_Image_Display Procedure

create or replace procedure my_image_display (fid in number)
as
  l_mime        varchar2 (255);
  l_length      number;
  lob_loc       blob;
  l_file_name          VARCHAR2 (2000); 
begin
  -- http://blog.hilandco.com/2010/05/how-to-show-blob-type-column-as-image.html
  select ATT_MIMETYPE, ATTACHMENT, dbms_lob.getlength (ATTACHMENT)
  into l_mime, lob_loc, l_length
  from  PRTL_FILES
  where file_id = fid;
   OWA_UTIL.mime_header (NVL (l_mime, 'application/octet'), FALSE);
   HTP.p ('Content-length: ' || l_length);
   OWA_UTIL.http_header_close;
   WPG_DOCLOAD.download_file (lob_loc);
end;


reference :


Comments

Popular posts from this blog

Customize Apex Login