in reply to Re: POST'ing a large File with LWP::UserAgent
in thread POST'ing a large File with LWP::UserAgent
#!/usr/bin/perl -- use strict; use warnings; use LWP 5.825; my $url = "http://foo/upload"; my $file = __FILE__;#"foo/bar"; my $ua = LWP::UserAgent->new; $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; use HTTP::Request::Common; my $req = POST( $url, Content_Type => 'multipart/form-data', Content => [ file => [$file] ], ); # set up callback { my $gen = $req->content(); die unless ref($gen) eq "CODE"; my $i = 0; $req->content( sub { my $chunk = &$gen(); # get chunk of data warn $i++; return $chunk; # send it to $url } ); #use Data::Dumper;die print Data::Dumper->new([($ua,$req, $gen)])->Ind +ent(1)->Deparse(1)->Dump; } my $res = $ua->request($req); #do it print $res->status_line;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: POST'ing a large File with LWP::UserAgent
by Anonymous Monk on Nov 30, 2011 at 06:34 UTC | |
by Anonymous Monk on Nov 30, 2011 at 08:32 UTC |
In Section
Seekers of Perl Wisdom