pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedBlobs with perl
4+ messages / 4 participants
[nested] [flat]
* Blobs with perl
@ 2003-06-17 09:00 cristi <cristi@dmhi.ct.ro>
2003-06-17 14:30 ` Re: Blobs with perl Jonathan Gardner <jgardner@jonathangardner.net>
2003-06-17 23:34 ` Re: Blobs with perl Michael A Nachbaur <mike@nachbaur.com>
0 siblings, 2 replies; 4+ messages in thread
From: cristi @ 2003-06-17 09:00 UTC (permalink / raw)
To: pgsql-sql
I want to insert a picture in a table from an internet browser using a
script made in perl.
Has somebody a code example with this kind a problem (I need only a code
fragment)?
Thanks!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Blobs with perl
2003-06-17 09:00 Blobs with perl cristi <cristi@dmhi.ct.ro>
@ 2003-06-17 14:30 ` Jonathan Gardner <jgardner@jonathangardner.net>
2003-06-17 23:18 ` Re: Blobs with perl Rudi Starcevic <rudi@oasis.net.au>
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Gardner @ 2003-06-17 14:30 UTC (permalink / raw)
To: cristi <cristi@dmhi.ct.ro>; pgsql-sql
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday 17 June 2003 02:00, cristi wrote:
> I want to insert a picture in a table from an internet browser using a
> script made in perl.
> Has somebody a code example with this kind a problem (I need only a code
> fragment)?
>
Despite PostgreSQL's powerful BLOB features, I would strongly suggest against
storing these kind of things in the database. It is better to have it in a
local file for several reasons.
1) Apache can server up local images lightning fast
2) You can edit local images with your favorite image editor (ie, Gimp,
Photoshop)
3) You can ftp, scp, sftp the image around without a problem.
4) You can tar it up and archive it.
5) You can move it off of your burdened PostgreSQL database server machine and
on to its own image server when your site becomes popular.
While all of the above are certainly possible with PostgreSQL, it is a bit
more complicated.
And remember, while your database server is small now, it will grow, and grow,
and grow, and grow. It will one day become the bottleneck in your operations.
That is an inevitable fact of any dynamic website.
- --
Jonathan Gardner <jgardner@jonathangardner.net>
(was jgardn@alumni.washington.edu)
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+7yYTWgwF3QvpWNwRAv3WAKDFrjfQUpQFmZFvVMismUeoxABoDQCfY/F7
LajclhvacQOgsn+6qnLEEwQ=
=k0vW
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Blobs with perl
2003-06-17 09:00 Blobs with perl cristi <cristi@dmhi.ct.ro>
2003-06-17 14:30 ` Re: Blobs with perl Jonathan Gardner <jgardner@jonathangardner.net>
@ 2003-06-17 23:18 ` Rudi Starcevic <rudi@oasis.net.au>
0 siblings, 0 replies; 4+ messages in thread
From: Rudi Starcevic @ 2003-06-17 23:18 UTC (permalink / raw)
To: ; +Cc: pgsql-sql
Hi,
For not so big applications you could consider converting the binary
image/file into text, using base64, then store the resulting text.
For example I have an app. where each member may have one or two images
on their account.
So when the user upload's their image I base64 it and store the text.
Then when we need to see the image select the text and decode it back to
binary format.
It work's well for me.
This way only text is stored. It's also handy as you don't need to worry
about file name's being the same.
It will increase the file size by about 30%.
Search the web for base64 example's, I'm sure you'll find examples to
work with.
You can email me off list if you like to see some PHP code which does this.
Cheers
Rudi.
Jonathan Gardner wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On Tuesday 17 June 2003 02:00, cristi wrote:
>
>
>>I want to insert a picture in a table from an internet browser using a
>>script made in perl.
>>Has somebody a code example with this kind a problem (I need only a code
>>fragment)?
>>
>>
>>
>
>Despite PostgreSQL's powerful BLOB features, I would strongly suggest against
>storing these kind of things in the database. It is better to have it in a
>local file for several reasons.
>
>1) Apache can server up local images lightning fast
>2) You can edit local images with your favorite image editor (ie, Gimp,
>Photoshop)
>3) You can ftp, scp, sftp the image around without a problem.
>4) You can tar it up and archive it.
>5) You can move it off of your burdened PostgreSQL database server machine and
>on to its own image server when your site becomes popular.
>
>While all of the above are certainly possible with PostgreSQL, it is a bit
>more complicated.
>
>And remember, while your database server is small now, it will grow, and grow,
>and grow, and grow. It will one day become the bottleneck in your operations.
>That is an inevitable fact of any dynamic website.
>
>- --
>Jonathan Gardner <jgardner@jonathangardner.net>
>(was jgardn@alumni.washington.edu)
>Live Free, Use Linux!
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.1 (GNU/Linux)
>
>iD8DBQE+7yYTWgwF3QvpWNwRAv3WAKDFrjfQUpQFmZFvVMismUeoxABoDQCfY/F7
>LajclhvacQOgsn+6qnLEEwQ=
>=k0vW
>-----END PGP SIGNATURE-----
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Blobs with perl
2003-06-17 09:00 Blobs with perl cristi <cristi@dmhi.ct.ro>
@ 2003-06-17 23:34 ` Michael A Nachbaur <mike@nachbaur.com>
1 sibling, 0 replies; 4+ messages in thread
From: Michael A Nachbaur @ 2003-06-17 23:34 UTC (permalink / raw)
To: cristi <cristi@dmhi.ct.ro>; pgsql-sql
On Tuesday 17 June 2003 02:00 am, cristi wrote:
> I want to insert a picture in a table from an internet browser using a
> script made in perl.
> Has somebody a code example with this kind a problem (I need only a code
> fragment)?
I put album covers into a database table, primarily because I wanted them
closely tied to database data without having any dependancy on a specific
filesystem structure. Anyway, performance isn't much to shout about, but
here's the relevant code snippet that I use to insert album images. It uses
LWP::UserAgent to download the jpeg, and then plug it into my database table:
my $insert_cover = $dbh->prepare(qq|
UPDATE Album
SET CoverLarge = ?
, CoverMedium = ?
, CoverSmall = ?
WHERE ID = ?
|);
my $small_url = "$image_url?S=$image_pid&X=60&Y=60";
my $medium_url = "$image_url?S=$image_pid&X=120&Y=120";
my $large_url = "$image_url?S=$image_pid&X=178&Y=178";
return unless ($image_pid);
#print "\$id = \"$id\"\n";
#print "\$small_url = \"$small_url\"\n";
#print "\$medium_url = \"$medium_url\"\n";
#print "\$large_url = \"$large_url\"\n";
my $small_image = $ua->get($small_url)->content;
my $medium_image = $ua->get($medium_url)->content;
my $large_image = $ua->get($large_url)->content;
$insert_cover->bind_param(1, $large_image, DBI::SQL_BINARY);
$insert_cover->bind_param(2, $medium_image, DBI::SQL_BINARY);
$insert_cover->bind_param(3, $small_image, DBI::SQL_BINARY);
$insert_cover->bind_param(4, $id);
$insert_cover->execute;
This comes from a throw-away script I whipped up to migrate from an older
system, so the code isn't all that clean (e.g. not commented, convoluted
variable names, etc) but it should get you started.
--
Michael A Nachbaur <mike@nachbaur.com>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-06-17 23:34 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-17 09:00 Blobs with perl cristi <cristi@dmhi.ct.ro>
2003-06-17 14:30 ` Jonathan Gardner <jgardner@jonathangardner.net>
2003-06-17 23:18 ` Rudi Starcevic <rudi@oasis.net.au>
2003-06-17 23:34 ` Michael A Nachbaur <mike@nachbaur.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox