Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

LWP Upload a file with a progress indicator

by zentara (Archbishop)
on Mar 04, 2005 at 11:56 UTC ( [id://436544]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, Someone asked elsewhere, about how to get a progress indicator on a file upload. I am not talking about using a browser, but with something like LWP or libCurl.

There seems to be a way with libCurl,according to the docs, but I have yet to get anything to work. There are so many interrealted libcurl options, I've havn't been able to get it to put out the right headers for a multipart form file upload, and I'm not even close tothe file part.

With LWP, it's quite easy to do the upload with HTTP::Request::Common, but it does not have a way to do "chunked uploads" where we can extract progress from. By looking at the docs, there is some mention of $DYNAMIC_FILE_UPLOAD, but I've yet to see a snippet which works.

A search on this topic is filled with people failing with libCurl scripts(written in PhP), and nothing for LWP using $DYNAMIC_FILE_UPLOAD.

So does anyone have a minimal script, showing how to upload a file with either libCurl, or LWP, and have a progress callback of some sort? I am still working on it, but I'm to the point of guessing at options and headers, :-) so I figure it's time to ask.

I'm not really a human, but I play one on earth. flash japh
  • Comment on LWP Upload a file with a progress indicator

Replies are listed 'Best First'.
Re: LWP Upload a file with a progress indicator
by beauregard (Monk) on Mar 04, 2005 at 13:46 UTC
    I've done a bit of work with this.. The basic idea is:
    $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; my $req = make_http_request(); my $gen = $req->content(); die unless ref($gen) eq "CODE"; $req->content( sub { my $chunk = &$gen(); print "." x (length($chunk)/1024) if defined $chunk; return $chunk; } ); my $res = $ua->request($req);
    This snippet will spit out a period for, more or less, each kilobyte uploaded. That's the theory. I've found that this isn't entirely reliable for every LWP implementation I've tried (not many, either).


      Thanks, that's just the kind of thing I needed to get me going. The Flickr-Upload is pretty new, I'll have to check it out.

      I'm not really a human, but I play one on earth. flash japh
      How can this acutally be used to resume a upload?
        you need ftp server

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://436544]
Approved by Joost
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-07-24 15:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.