From: Michael A Nachbaur <mike@nachbaur.com>
To: cristi <cristi@dmhi.ct.ro>
To: pgsql-sql@postgresql.org
Subject: Re: Blobs with perl
Date: Tue, 17 Jun 2003 16:34:15 -0700
Message-ID: <200306171634.15281.mike@nachbaur.com> (raw)
In-Reply-To: <00e001c334ae$d93e52c0$7201a8c0@aaa>
References: <00e001c334ae$d93e52c0$7201a8c0@aaa>
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>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@nachbaur.com, cristi@dmhi.ct.ro
Subject: Re: Blobs with perl
In-Reply-To: <200306171634.15281.mike@nachbaur.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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