Re: how to display BLOB/BFILE in web browser

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 26 Nov 1999 09:34:45 -0500
Message-ID: <fj6t3skfs5g0s9gusm7pkrrhbbrmsgphoh_at_4ax.com>


A copy of this was sent to Harlin Setiadarma <harlins_at_bigfoot.com> (if that email address didn't require changing) On Fri, 26 Nov 1999 10:56:53 +0700, you wrote:

>Why you only get 30 bytes (l_amt defaulted to 30) in the first loop,
>then get 4096 bytes of data in the next loop.
>Why not you default l_amt to 4096 at first time.
>

because in order to test it, i initially set the raw size to 30 bytes to ensure it would work for objects bigger then my buffer. i later reset the sizeof the raw to 4k for a little performance (could be upto 32k) but didn't reset the initial read size. no real reason, it could be/should be 4k each time.

>Thanks.
>Harlin.
>
>On Sat, 06 Nov 1999 10:26:29 -0500, Thomas Kyte <tkyte_at_us.oracle.com>
>wrote:
>
>>A copy of this was sent to "Lydia A. Gleba" <lag_at_andrew.cmu.edu>
>>(if that email address didn't require changing)
>>On Fri, 05 Nov 1999 17:25:08 -0500, you wrote:
>>
>>>How do I get BFILE/BLOB data out of the database and displayed in the
>>>web browser?
>>>
>>>(We stored a .jpg image as a bfile and we're trying to use a PL/SQL
>>>procedure to display the image using OAS4 and "<img SRC = "the PL/SQL
>>>procedure call">" in our html file. Is this the right approach?)
>>
>>
>>it would look something like this:
>>
>>
>>create or replace package image_get
>>as
>>
>> procedure gif( p_id in demo.id%type );
>>
>>end;
>>/
>>
>>create or replace package body image_get
>>as
>>
>>procedure gif( p_id in demo.id%type )
>>is
>> l_lob blob;
>> l_amt number default 30;
>> l_off number default 1;
>> l_raw raw(4096);
>>begin
>> select theBlob into l_lob
>> from demo
>> where id = p_id;
>>
>> owa_util.mime_header( 'image/gif' );
>>
>> begin
>> loop
>> dbms_lob.read( l_lob, 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;
>>end;
>>
>>end;
>>/
>>
>>
>>Assuming you had a table like "DEMO ( id int primary key, theBlob blob )" a URL
>>like:
>>
>><img src=/..../image_get.gif?id=55>
>>
>>would retrieve the row with a key of 55 and display it.
>>
>>If UTL_RAW is not installed on your system (part of the replication package)
>>install it by looking in $ORACLE_HOME/rdbms/admin for "*raw*". you'll find the
>>spec and body (.sql and .plb files). run them using SVRMGRL when connected as
>>SYS or INTERNAL (and NOT any other account, only sys or internal or you'll get
>>runtime errors about missing icd vectors and such).
>>
>>Also note that the NLS_LANG of the webserver MUST BE the same as the NLS_LANG of
>>the database else this little trick won't work as SQLNet will convert the blob
>>instream . this frequently occurs with a UNIX database (defaults to us7ascii)
>>and NT which defaults to an 8bit character set. You'll get bits stripped off,
>>apparently corrupting the image since we are using VARCHARs in the HTP packages.

-- 
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Fri Nov 26 1999 - 15:34:45 CET

Original text of this message