Re: how to display BLOB/BFILE in web browser

From: Harlin Setiadarma <harlins_at_bigfoot.com>
Date: Fri, 26 Nov 1999 10:56:53 +0700
Message-ID: <m71s3s4qoj95hj9jdds43k0j1nast7cq1u_at_4ax.com>


[Quoted] 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.

Thanks.
Harlin.

[Quoted] 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.
Received on Fri Nov 26 1999 - 04:56:53 CET

Original text of this message