http://www.perlmonks.org?node_id=928100

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

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?

Replies are listed 'Best First'.
Re: MediaWiki::API->upload() problem
by choroba (Cardinal) 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