Thread: bytea / large object and image

bytea / large object and image

From
"Alain Roger"
Date:
Hi,

I create a table with some large object (ref: OID) to store some images.
When my PHP will display some data, it will also display the images stored as OID.

However, i've read that before i must restore the image by exporting them to local (on server) file.

isn't it easier in this case, to simply store the path and file name of file to DB and just read the data to display image on PHP pages ?
what is the purpose in this case to store image a bytea / large object ?

thanks a lot,

Al.

Re: bytea / large object and image

From
"Raymond O'Donnell"
Date:
On 4 Nov 2006 at 18:24, Alain Roger wrote:

> However, i've read that before i must restore the image by exporting
> them to local (on server) file.

You can use bytea type to store binary data directly in the database -
 if it's any use to you, I can send you some ASP code that does this.

There was a thread recently on the merits of doing it this way, as
opposed to storing the image on the filesystem and keeping just
metadata in the DB - you'll find it in the archives.

--Ray.



----------------------------------------------------------------------

Raymond O'Donnell
Director of Music, Galway Cathedral, Galway, Ireland
rod@iol.ie
----------------------------------------------------------------------



Re: bytea / large object and image

From
Tomas Vondra
Date:
> Hi,
>
> I create a table with some large object (ref: OID) to store some images.
> When my PHP will display some data, it will also display the images
> stored as OID.
>
> However, i've read that before i must restore the image by exporting
> them to local (on server) file.

I'm not sure what you mean by 'exporting to local file'. You don't have
to store each image in a separate file, you can store them in a bytea
column, use a script to load the data and send them to the client.

The point is you can't write them with the other data (HTML tags, text
etc) as the browsers handle images as separate objects using the <img>
tag. So all you have to do is basically something like this

<?php

   // load the image data from the database
   $sql = 'SELECT image_data FROM images WHERE id = ' . $id;
   ... do the SQL

   // send them to the client
   head('Content-type: image/png'); // set the correct mime-type
   echo $imageData;

?>

That's all.

> isn't it easier in this case, to simply store the path and file name of
> file to DB and just read the data to display image on PHP pages ?
> what is the purpose in this case to store image a bytea / large object ?

This is true in case of 'dumb' databases as for example MySQL, as these
databases handle LOB columns pretty bad.

Tomas

Re: bytea / large object and image

From
"Joshua D. Drake"
Date:
Raymond O'Donnell wrote:
> On 4 Nov 2006 at 18:24, Alain Roger wrote:
>
>> However, i've read that before i must restore the image by exporting
>> them to local (on server) file.
>
> You can use bytea type to store binary data directly in the database -
>  if it's any use to you, I can send you some ASP code that does this.

bytea is not always a good idea. It depends on the size of the data you
are storing. If you are storing pretty much anything greater than 200k I
would suggest moving to pg_largeobject instead.

Joshua D. Drake



>
> There was a thread recently on the merits of doing it this way, as
> opposed to storing the image on the filesystem and keeping just
> metadata in the DB - you'll find it in the archives.
>
> --Ray.
>
>
>
> ----------------------------------------------------------------------
>
> Raymond O'Donnell
> Director of Music, Galway Cathedral, Galway, Ireland
> rod@iol.ie
> ----------------------------------------------------------------------
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly
>


--

SPI Liason, PostgreSQL Fundraising Group
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
Find out about PostgreSQL Fundraising: http://fundraising.postgresql.org/
Read the PostgreSQL docs: http://www.postgresql.org/docs/