Skip to Main Content
  • Questions
  • blob displays unprintable characters on a web page

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Les.

Asked: October 24, 2001 - 11:10 am UTC

Last updated: July 08, 2005 - 6:41 pm UTC

Version: 8.1.7.0.0

Viewed 1000+ times

You Asked

Good monring Tom,

I have used some of your previous answers, and hence I am able to
populate a blob column. I know it is populated because when I put character data in it, my web page shows the length and the characters.
However, when I put a jpg or gif in it, the length is shown, but the gif or jpg show up as if it was being edited by something like word pad. The image is returned as uprintable characters. This happens on both netscape 4 and ie 4.

Here is the code I am using to display the image:

procedure gif( p_id in web_picts.pic_id%type )
is
l_lob blob;
buffer raw(32000);
buffer_size integer := 32000;
offset integer := 1;
length number(8);
begin
owa_util.mime_header('image/gif');
select picture into l_lob
from web_picts
where pic_id = p_id;
length := dbms_lob.getlength(l_lob);
while offset < length loop
dbms_lob.read(l_lob, buffer_size, offset, buffer);
htp.p('Picture Length ' || length);
--htp.p(l_lob);
htp.prn(utl_raw.cast_to_varchar2(buffer));
offset := offset + buffer_size;
end loop;
exception
when others then
htp.p(sqlerrm);
end;

And here is the code that calls the above:

Procedure home

is

theImage blob;
Begin
htp.p ('test...just to be sure a page is showing');
image_get.gif(1);

Exception
When others Then
null ;
End;

The above is a condensed example dealing with only getting the blob.

This is what the web page shows for the image:

test...just to be sure a page is showing Content-type: image/gif Picture Length 17050
ÿØÿà‘¡±B#$RÁb34r‚ÑC%’Sðáñcs5¢²ƒ&D“TdE£t6ÒUâeò³„ÃÓuãóF'”¤…´•ÄÔäô¥µÅÕåõVfv†–¦¶ÆÖæö7GWgw‡—§·Ç×ç÷UËk7HqLyÙ»Wåî)32ÀdsÒLH7í,òÔn–Ú}²>¥sqÆùÝRS§ŽÙ¸q9q9ù̦w&þO
©} B’„'¡)zÓ‡hÁ©+ætŽ.vekbö”ùÈó
7Ö®u~K–µkU[n¿?ó‰µî:«1N’*²*u”P„P„P„P„P„P„P„P…«?€‰2R§
'§¤Ô3I¤,ÐñXùù%ˆøñåGOç+úë€Üww=Ä4égÄäÎÖÃV%6Àù`ÚÒ!õ¬žzx~ÚK¬”Ëíãnem1ò×
?5´Ué*?º±Ä³H‡búvîʎt8üD*ײÝ@6õª³¡Ë4C±ª0Û5õ†#®+î(!§¥pô$šÁ


This happens on both the server machine and my work machine, so I think it is a setting of some kind...something simple.

At any rate, many thanks in advance for any assistance you may offer.

Les Davidner





and Tom said...

The procedure that "calls" it should be:

Procedure home
is
theImage blob;
Begin
htp.p ('test...just to be sure a page is showing');
htp.p( '<img src=image_get.gif?p_id=1>' );
Exception
When others Then
null ;
End;

you yourself will NEVER call image_get.gif -- the web browser will. Think about if, if you made a static web page -- just an html file, you would never "read the jpg" into the HTML right? your home procedure does that -- reads the jpg right into the html. You want to generate HTML that references via the IMG tag the jpg.




Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Helpful but need an example

Joyce Fowler, February 19, 2003 - 4:22 pm UTC

I have PL/SQL procedures to create a table with a BLOB field and a procedure to load images into that table. But I am having trouble displaying those images in a Browser.
You said "You want to generate HTML that references via the IMG tag the jpg." How to I do this in HTML where an image is called from the database and displayed in a Browser? Do I use a procedure call???? There is <IMG SRC=<procedure call>"> Do you have any example of using this?
Thanks,

Moving code to 10g

Les Davidner, July 08, 2005 - 5:46 pm UTC

Hi Tom,

It was I who had originally got your kind assistance with displaying an image on a web page via this question along with a few others. Your answer here was what made it all seem to make sense. This works perfectly in everything form 8.1.7. to 9.2.0.6.0. as you can see by my demo page. Feel free to look around. : </code> http://68.145.41.85/pls/blobdemo/blobman.blobmaint.home <code>which is currently 9.2.0.4.0.

Every image that goes into the page is stored in the database, as well as all the other blob stuff. Totally awesome. I wanted to port my code to 10g. After doing this, none of the images show up. All the pages work, except the images are shown as broken links. I successfully add a new image (I am guessing it is successful because I display the size and it seems correct), and it is displayed as a broken image. I add a text file however, and I can get it back on my web page. I did not make any code changes and everything compiled without any warnings or errors, I actually used the locked plb file from 9.2.0.4.0 for this. I am at a loss for a reason as to why this is happening. Is there any chance you may know what I may have missed or did not configure correctly.

Many thanks in advance Tom.

Les Davidner

Tom Kyte
July 08, 2005 - 6:41 pm UTC

check out your charactersets

if you are using the old fashioned way

</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:232814159006#6891533553691 <code>

is infinitely superior.



but make sure db character set = CLIENT (web server) character set. that seems the most likely cause.

Moving code to 10g

Les Davidner, July 10, 2005 - 4:00 pm UTC

Hi Tom,

Character set was in fact the issue. It seems that this was in the DAD:

PlsqlNLSLanguage AMERICAN_AMERICA.US7ASCII

Without it all seems well.

Many thanks for your kind and prompt assistance with this.

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here