Home » Fusion Middleware & Colab Suite » WebCenter Suite & Portal » loading the BFILE-stored picture into HTML
loading the BFILE-stored picture into HTML [message #146247] Wed, 09 November 2005 09:29 Go to next message
Herr Svami
Messages: 3
Registered: October 2005
Location: Kiev, Ukraine
Junior Member
How I can load the BFILE-stored picture into HTML page
whith PL/SQL methods?

PS: Sorry, my English isn't good
Embarassed
Re: loading the BFILE-stored picture into HTML [message #147475 is a reply to message #146247] Thu, 17 November 2005 15:54 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Something like this should work...
--from DBA account:
grant create any directory to SCOTT;

--from Code owner (SCOTT)
create or replace directory my_files as '/tmp';
--grant read on directory my_files to public;

CREATE OR REPLACE PROCEDURE SCOTT.show_img
AS
   l_blob    BLOB;
   l_bfile   BFILE;
   l_amt     NUMBER     DEFAULT 30;
   l_off     NUMBER     DEFAULT 1;
   l_raw     RAW (4096);
BEGIN
   -- just to demonstrate that the HTML and image are separate.
   -- dbms_lock.sleep(5);
   DBMS_LOB.createtemporary (l_blob, TRUE, DBMS_LOB.SESSION);
   l_bfile := BFILENAME ('MY_FILES', 'my_pic.jpg');
   DBMS_LOB.fileopen (l_bfile);
   DBMS_LOB.loadfromfile (l_blob, l_bfile, DBMS_LOB.getlength (l_bfile));
   DBMS_LOB.fileclose (l_bfile);
   OWA_UTIL.mime_header ('image/jpeg');

   LOOP
      DBMS_LOB.READ (l_blob, l_amt, l_off, l_raw);
      HTP.prn (UTL_RAW.cast_to_varchar2 (l_raw));
      l_off := l_off + l_amt;
      l_amt := 4096;
   END LOOP;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      NULL;
END;
/

-- this illustrates how the HTML can be separate from the image
CREATE OR REPLACE PROCEDURE SCOTT.show_img1
AS
BEGIN
htp.p('<HTML><BODY><HEAD><TITLE>Image Test Page - with text</TITLE></HEAD>');
htp.p('Below is an immage<br>');
htp.p('<img src="SCOTT.show_img" alt="my immage" border="0"><br>');
--img is an alias to where the images are
--htp.p('<img src="http://myserver:7777/img/my_pic.jpg" alt="my immage" border="0"><br>');
htp.p('Above is an immage<br></BODY></HTML>');
END;
/

grant execute on show_img to public;
grant execute on show_img1 to public;

-- make sure the file exists
/tmp/my_pic.jpg


-- view it 
http://myserver:7777/pls/mydad/SCOTT.show_img1

Previous Topic: Urgent and Important - Sequence of scripts to start portal server
Next Topic: Oracle 9i File Uploading Problem
Goto Forum:
  


Current Time: Mon Nov 25 12:44:57 CST 2024