Can I Save images in postgres?

Started by 纪晓曦over 16 years ago6 messagesgeneral
Jump to latest
#1纪晓曦
sheepjxx@gmail.com

Can I save images in the postgres? How to define? Does the format matters?
Can I save JPG/PNG?How?

#2John R Pierce
pierce@hogranch.com
In reply to: 纪晓曦 (#1)
Re: Can I Save images in postgres?

纪晓曦 wrote:

Can I save images in the postgres? How to define? Does the format
matters? Can I save JPG/PNG?How?

you can save images as BYTEA data, and the format is totally up to your
application, as postgres just treats it as a block of bytes. however,
I generally find it easier to store my images on a file system, and just
put the file path in the database.

#3Yaroslav Tykhiy
yar@barnet.com.au
In reply to: John R Pierce (#2)
Re: Can I Save images in postgres?

On 09/09/2009, at 10:43 AM, John R Pierce wrote:

纪晓曦 wrote:

Can I save images in the postgres? How to define? Does the format
matters? Can I save JPG/PNG?How?

you can save images as BYTEA data, and the format is totally up to
your application, as postgres just treats it as a block of bytes.
however, I generally find it easier to store my images on a file
system, and just put the file path in the database.

By the way, here's a relatively recent discussion of this issue:

http://archives.postgresql.org/pgsql-general/2009-06/msg00599.php

Yar

#4纪晓曦
sheepjxx@gmail.com
In reply to: Yaroslav Tykhiy (#3)
Re: Can I Save images in postgres?

Thank you very much. It seems it is better to save it on file system.

2009/9/9 Yaroslav Tykhiy <yar@barnet.com.au>

Show quoted text

On 09/09/2009, at 10:43 AM, John R Pierce wrote:

纪晓曦 wrote:

Can I save images in the postgres? How to define? Does the format
matters? Can I save JPG/PNG?How?

you can save images as BYTEA data, and the format is totally up to your
application, as postgres just treats it as a block of bytes. however, I
generally find it easier to store my images on a file system, and just put
the file path in the database.

By the way, here's a relatively recent discussion of this issue:

http://archives.postgresql.org/pgsql-general/2009-06/msg00599.php

Yar

#5Jasen Betts
jasen@xnet.co.nz
In reply to: 纪晓曦 (#1)
Re: Can I Save images in postgres?

On 2009-09-09, 纪晓曦 <sheepjxx@gmail.com> wrote:

--001636834258521c91047319fd34
Content-Type: text/plain; charset=ISO-8859-1

Can I save images in the postgres?

yes.

How to define?

a bytea column it probably a good start

Does the format matters?

not to postgres.

base64 or hex encoding and storing in a text filed also works.

#6Jasen Betts
jasen@xnet.co.nz
In reply to: 纪晓曦 (#1)
Re: Can I Save images in postgres?

On 2009-09-09, John R Pierce <pierce@hogranch.com> wrote:

纪晓曦 wrote:

Can I save images in the postgres? How to define? Does the format
matters? Can I save JPG/PNG?How?

you can save images as BYTEA data, and the format is totally up to your
application, as postgres just treats it as a block of bytes. however,
I generally find it easier to store my images on a file system, and just
put the file path in the database.

storing images in the database is useful when providing filesystem
access to a shared location is inconvenient, and also helps with data
integrity.