Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: POST'ing a large File with LWP::UserAgent

by Anonymous Monk
on May 03, 2009 at 06:59 UTC ( #761562=note: print w/ replies, xml ) Need Help??


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;


Comment on Re^2: POST'ing a large File with LWP::UserAgent
Download Code
Re^3: POST'ing a large File with LWP::UserAgent
by Anonymous Monk on Nov 30, 2011 at 06:34 UTC

    Thanks for the feed back. Hi can you explain what the below code actually do

    # 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 } );

      Thanks for the feed back. Hi can you explain what the below code actually do

      Hi. There is no way you were overrider ;)

      The code saves the default (DYNAMIC_FILE_UPLOAD) callback for uploading a large file, and wraps it in another callback, which invokes the original callback, but also counts the number of times it was called, and reports the number stderr

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-09-02 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (31 votes), past polls