Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi Guys,

After a day of trying playing around with every option I could find, I came up with the following. The nice thing is that it has progress reporting.

Thanks for everyone's help,



#!/usr/bin/perl -w use strict; use warnings; use WWW::Curl::Easy; # set custom HTTP request header fields my $url = ""; my $token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; my $filetype_to_upload="pdf"; my $file_to_upload="/path/to/file.$filetype_to_upload"; my $size = -s $file_to_upload; open( IN, $file_to_upload ) or die("Cannot open file - $file_to_upload +. $! \n"); my $curl = WWW::Curl::Easy->new or die $!; # Headers. my @request_header = (); #push (@request_header, "Accept-Encoding: gzip"); push (@request_header, "Content-type: multipart/form-data; boundary=fr +ontier"); push (@request_header, "Authorization: Token $token"); push (@request_header, "User-Agent: Perl interface for libcURL/7.35.0" +); # Options my $retcode ; $retcode = $curl->setopt(CURLOPT_POST, 1); $retcode = $curl->setopt(CURLOPT_VERBOSE,0); $retcode = $curl->setopt(CURLOPT_HEADER(), 1); $retcode = $curl->setopt(CURLOPT_HTTPHEADER, \@request_header); $retcode = $curl->setopt(CURLOPT_URL(), $url); $retcode = $curl->setopt(CURLOPT_NOPROGRESS, 0); $retcode = $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&progress_callback +); $retcode = $curl->setopt( CURLOPT_INFILESIZE, $size ); $retcode = $curl->setopt( CURLOPT_UPLOAD, 1 ); $retcode = $curl->setopt( CURLOPT_CUSTOMREQUEST, 'POST' ); $retcode = $curl->setopt(CURLOPT_TIMEOUT, 30); $curl->setopt(CURLOPT_READDATA, \*IN); $curl->setopt( CURLOPT_POSTFIELDSIZE_LARGE, -1 ); $retcode = $curl->perform; if ($retcode == 0) { print("File upload success\n"); } else { print("An error happened: $retcode ".$curl->strerror($retcode)."\n +"); } exit; sub progress_callback { my ($clientp,$dltotal,$dlnow,$ultotal,$ulnow)=@_; if ($ultotal) { print int (100 * $ulnow/$ultotal), "% Complete.\n"; } else { print "0% Complete.\n"; } return 0; }

In reply to Re: XPOST syntax in WWW::Curl by Steve_BZ
in thread XPOST syntax in WWW::Curl by Steve_BZ

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-06-20 01:21 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.