|
Re: loading the BFILE-stored picture into HTML [message #147475 is a reply to message #146247] |
Thu, 17 November 2005 15:54 |
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
|
|
|