Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

All,

I get 100s of images every month that needs to be uploaded to the server. The local image path location will be available in a DB table. So we would be like to select the image path and file name from the DB table and read that file and then upload the file to a particular location in the external server (which requires a username & passwors). Would require your guidance (plain perl and image-magick) that can automate the uploading process.

Regards,

Replies are listed 'Best First'.
Re: How to upload bulk images
by marto (Cardinal) on Jan 02, 2008 at 13:55 UTC
    How do you connect to the server to upload the files? If you use FTP then you should look at the Net::FTP module. If uploading is done via browser then WWW::Mechanize should be a good place to start. Databases can be queried and manipulated by using DBI. Do you wish to edit these image prior to upload? I am curious as to why you have mentioned imagemagick.

    Should you need help installing modules read Installing Modules from the tutorials section of this site.

    Hope this helps

    Update: Fixed typo.

    Martin
Re: How to upload bulk images
by zentara (Cardinal) on Jan 02, 2008 at 16:57 UTC
    Hi, this script will work with plain http (it's shown as https). It shows the basics. You can put the upload in a loop to upload multiple files. For more examples, search groups.google.com for "lwp upload".
    #!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common qw(POST); my $https_url = 'https://zentara.zentara.net/~zentara/cgi-bin/uploads/ +up1.cgi'; my $https_user = 'zentara'; my $https_pass = 'foobar'; my $file = 'testout.tgz'; &postHTTPS(); sub postHTTPS { my $ua = new LWP::UserAgent; $ua->protocols_allowed( [ 'https'] ); $ua->cookie_jar(HTTP::Cookies->new(file =>".cookies.txt",autos +ave => 1)); #setup request my $req = POST($https_url, Content_Type => 'multipart/form-data', Content =>[ file =>[ $file ], ], ); #setup auth $req->authorization_basic($https_user, $https_pass); #do post my $response = $ua->request($req); if ($response->is_error()) { printf " %s\n", $response->status_line; print "https request error!\n"; } else { my $content = $response->content(); print "$content\n"; } if ( $response->is_success ) { print $response->as_string; }else { print $response->status_line; } }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Thank you all. The server is Windows (DB is MS-SQL Server, which I will connect using DBI).
        If possible I would like to reduce the image size, that is why I had mentioned image-magick. But if it can be done using plain PERL, GREAT. Thanks
A reply falls below the community's threshold of quality. You may see it by logging in.