Re: Storing jpgs

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: C G <csgcsg39(at)hotmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Storing jpgs
Date: 2004-04-05 17:04:12
Message-ID: Pine.LNX.4.33.0404051057390.13872-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 5 Apr 2004, C G wrote:

> Dear All,
>
> What's the best way to store jpgs in postgresql to use in a web page?
>
> I tried to use large objects, but how would you extract them from a table to
> be viewed in a web-page without having to write them to a scratch file
> somewhere first?

There are several ways to skin this cat, and your choice depends largely
on what type of system you'll be deploying.

Will you have more than one front end server? If so, will they be able to
share a network file system mount for the files? Then the preferred
method for many people is to store the jpg in the file system with a path
in the database. If you can't mount the same point from multiple servers
(or don't want to) then you'll need to store them in the database.

However, maybe you want to be able to update multiple jpegs at the same
time in a transaction? then storing them in either a bytea field or
base64 encoded in a text field will work well.

Storing them as base64 or as a path with a file system is likely more
portable than using large objects. Also, you have to dump large
objects seperately, so your backup process may be more complicated than
you want.

As for displaying them whether you store them as bytea, base64 encoded
text, or large objects, most languages will allow you to build and deliver
an image without having to write it to some temporary place.

Here's a simple example from PHPBuilder on doing it with the file path in
the database, and using a directory of files that may lie outside the
documentroot of apache:

http://www.phpbuilder.com/board/showthread.php?s=&postid=10497815#post10497815

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lamar Owen 2004-04-05 17:41:40 Re: RPM init-script: Why the locale setting?
Previous Message Rod K 2004-04-05 16:58:00 Re: Storing jpgs