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

MediaWiki::API->upload() problem

by spekulum (Initiate)
on Sep 27, 2011 at 15:17 UTC ( #928100=perlquestion: print w/replies, xml ) Need Help??
spekulum has asked for the wisdom of the Perl Monks concerning the following question:

I use upload function from MediaWiki::API Module ( 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 '' 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/ line 91".

All perl modules is up to date.

How to resolve this problem?

Replies are listed 'Best First'.
Re: MediaWiki::API->upload() problem
by choroba (Bishop) on Sep 27, 2011 at 15:22 UTC

      Yes, and I don't find solutions on old threads.

        Yes, and I don't find solutions on old threads.

        What do you mean?

        The solution is to only give bytes not utf or decoded_content

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928100]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-02-18 23:08 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (257 votes). Check out past polls.