Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Anonymous Monk
on May 03, 2009 at 06:59 UTC ( [id://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;

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

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://761562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found