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

hi,
I want to automate http file uploads (may require authorization too), how u do this ?
I know there was a module if u can tell me his name and/or some code snippet it will ok.

Replies are listed 'Best First'.
Re: automating web upload ?
by bart (Canon) on May 13, 2005 at 09:27 UTC
    For automating web based task, LWP is the basic suite. File upload is a form of POST, you still have to compose the upload "message body".

    A web search revealed that the script cpan-upload makes use of an LWP::UserAgent to upload files: check the sub pause_add_files.

Re: automating web upload ?
by marto (Cardinal) on May 13, 2005 at 09:20 UTC
    Hi,

    If you read this node it should get you started as far as uploading via http.

    Cheers,
    marto
Re: automating web upload ?
by Fang (Pilgrim) on May 13, 2005 at 09:17 UTC
Re: automating web upload ?
by zentara (Cardinal) on May 13, 2005 at 11:24 UTC
    You are advised to use LWP. Here is a sample. It works, but I just threw in the authorization lines, you may need to tweak them.
    #!/usr/bin/perl use warnings; use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $url ='http://zentara.zentara.net/~zentara/cgi-bin/uploadz'; my $file = 'testout.tgz'; my $ua = new LWP::UserAgent; my $req = POST $url, Content_Type => 'multipart/form-data', Content => [ file => [$file] ]; #untested auth code my $user = 'zentara'; my $pass = 'foobar'; $req->authorization_basic($user, $pass); my $res = $ua->request($req); if ($res->is_success){print $res->as_string; }else{print $res->status_line; } exit 0;

    I'm not really a human, but I play one on earth. flash japh
Re: automating web upload ?
by zentara (Cardinal) on May 13, 2005 at 11:36 UTC
Re: automating web upload ?
by Anonymous Monk on May 27, 2005 at 00:57 UTC
    This script is a great help. Could you let me know what this will work w/ on the server side. In other words, what does the cgi file "uploadz" look like? Your guidance is needed and apreciated. thanks