X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id B718630DC8A for ; Tue, 17 Jun 2003 23:34:28 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 08025-02 for ; Tue, 17 Jun 2003 20:34:18 -0300 (ADT) Received: from dbdevel.sunwave.net (h64-141-16-15.sunwave.net [64.141.16.15]) by svr1.postgresql.org (Postfix) with ESMTP id 0241A30F27D for ; Tue, 17 Jun 2003 20:34:15 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by dbdevel.sunwave.net (Postfix) with ESMTP id 6AA65178008; Tue, 17 Jun 2003 19:34:15 -0400 (EDT) From: Michael A Nachbaur To: "cristi" , Subject: Re: Blobs with perl Date: Tue, 17 Jun 2003 16:34:15 -0700 User-Agent: KMail/1.5 References: <00e001c334ae$d93e52c0$7201a8c0@aaa> In-Reply-To: <00e001c334ae$d93e52c0$7201a8c0@aaa> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200306171634.15281.mike@nachbaur.com> X-Archive-Number: 200306/208 X-Sequence-Number: 13966 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