From: | Michael A Nachbaur <mike(at)nachbaur(dot)com> |
---|---|
To: | "cristi" <cristi(at)dmhi(dot)ct(dot)ro>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Blobs with perl |
Date: | 2003-06-17 23:34:15 |
Message-ID: | 200306171634.15281.mike@nachbaur.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)nachbaur(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-06-17 23:50:31 | Re: yet pg_toast reindex |
Previous Message | weigelt | 2003-06-17 23:34:06 | Re: [ADMIN] Can the frontend get notifications from the postgres server? |