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 <[EMAIL PROTECTED]>


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to