I use upload function from MediaWiki::API Module (http://search.cpan.org/~exobuzz/MediaWiki-API-0.27/lib/MediaWiki/API.pm) in a subroutine:

sub up_file { my ($api, $name, $url, $sum, $reupload) = @_; my $res = $api->api({ action => 'query', prop => 'info', titles => $name }) || return $api->{error}->{details}; my $missing = exists((values %{$res->{query}->{pages}})[0]->{missi +ng}); my $ua = LWP::UserAgent->new( timeout => 25 ); my $response = $ua->get($url); $response = $response->decoded_content if($response->is_success()) +; if((!$missing && $reupload) || $missing) { $api->edit({ action => 'upload', filename => $name, comment => $sum, text => $sum, file => $response, ignorewarnings => 1 }) || return 'Error with upload file ' . $name . ': ' . $api-> +{error}->{details}; return 'done'; } return 'File ' . $name . ' exist and $reupload is undefined'; }

$api is MediaWiki::API object, defined in main programm.

$name is full in-wiki filename like 'File:Example.jpg'.

$url is a real URL like 'http://example.com/1.jpg' to download file and send content to $api->upload() function.

$sum is a comment to uploading.

if $reupload is defined, this function can reupload exist file.

 

And this function with all correct variables return "HTTP::Message content must be bytes at /usr/local/share/perl/5.10.0/HTTP/Request/Common.pm line 91".

All perl modules is up to date.

How to resolve this problem?


In reply to MediaWiki::API->upload() problem by spekulum

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.