You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Gerardo Schimpf <sc...@bibleinfo.com> on 2002/11/04 18:34:07 UTC

Display Blob from database

Hello embperl fans!. I have a mysql table with a blob data type column and 
pictures stores in that column. How can I upload a picture and insert it into 
that column and display the picture on a HTML page?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Display Blob from database

Posted by Wim Kerkhoff <wi...@nyetwork.org>.
Kee Hinckley wrote:

> At 5:36 PM -0800 11/4/02, Andrew Lim wrote:
>
>> I need to do this thing pretty soon for my new project.
>> I still don't get this instruction.
>> Specially how to "SPIT out" image from DB and while() part.
>>
>> Can you give us more detailed explanation?
>
>
> Not really, since I don't know what API you are using to retrieve 
> items from the database.  The URL to the script needs to be passed the 
> id of the database element.  The script itself needs to lookup the id 
> in the database, retrieve the field that contains the image, and print 
> it.

Exactly. Every database seems to have a different way of handling binary 
large objects. If using DBI, see the man page for the DBD driver that is 
being used (e.g. DBD::Oracle or DBD::mysql).

With some databases, it's as easy as doing:

print $dbh->selectrow_array("select image from content_images where 
id=12345");

With other database drivers, blobs get treated more like file handles, 
requiring data to be read into a temporary buffer, one chunk at a time. 
Typically, there are lots of examples and discussions of the pitfalls of 
BLOBs in various mailing list that can be found via Google.




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Display Blob from database

Posted by Kee Hinckley <na...@somewhere.com>.
At 5:36 PM -0800 11/4/02, Andrew Lim wrote:
>I need to do this thing pretty soon for my new project.
>I still don't get this instruction.
>Specially how to "SPIT out" image from DB and while() part.
>
>Can you give us more detailed explanation?

Not really, since I don't know what API you are using to retrieve 
items from the database.  The URL to the script needs to be passed 
the id of the database element.  The script itself needs to lookup 
the id in the database, retrieve the field that contains the image, 
and print it.
-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Display Blob from database

Posted by Andrew Lim <an...@caltan.com>.
I need to do this thing pretty soon for my new project.
I still don't get this instruction.
Specially how to "SPIT out" image from DB and while() part.

Can you give us more detailed explanation?

Thanks

Andy


-----Original Message-----
From: Kee Hinckley [mailto:nazgul@somewhere.com]
Sent: Monday, November 04, 2002 9:43 AM
To: schige@bibleinfo.com
Cc: embperl@perl.apache.org
Subject: Re: Display Blob from database


At 9:34 AM -0800 11/4/02, Gerardo Schimpf wrote:
>Hello embperl fans!. I have a mysql table with a blob data type column and
>pictures stores in that column. How can I upload a picture and insert it
into
>that column and display the picture on a HTML page?

Uploading the picture you can do using test/html/upload.htm as an example.
Read the file in, stuff the bits in the database.
Displaying is a two part process.  The HTML page should have a reference
like:
	<img src="/foo.html?imageid=xxx">
and foo.html should consist of nothing except embperl code, like so:
[-
	$http_headers_out{'Content-Type'} = 'image/xxx';
	$http_headers_out{'Content-Length'} = yyy;
	spit out image data from database
	while (...) { print OUT xxx; }
	Apache::exit();
-]

You probably don't need the exit, I just do it to make sure no more
data ends up on the output stream.
--

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Display Blob from database

Posted by Kee Hinckley <na...@somewhere.com>.
At 9:34 AM -0800 11/4/02, Gerardo Schimpf wrote:
>Hello embperl fans!. I have a mysql table with a blob data type column and
>pictures stores in that column. How can I upload a picture and insert it into
>that column and display the picture on a HTML page?

Uploading the picture you can do using test/html/upload.htm as an example.
Read the file in, stuff the bits in the database.
Displaying is a two part process.  The HTML page should have a reference like:
	<img src="/foo.html?imageid=xxx">
and foo.html should consist of nothing except embperl code, like so:
[-
	$http_headers_out{'Content-Type'} = 'image/xxx';
	$http_headers_out{'Content-Length'} = yyy;
	spit out image data from database
	while (...) { print OUT xxx; }
	Apache::exit();
-]

You probably don't need the exit, I just do it to make sure no more 
data ends up on the output stream.
-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org