Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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 (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?

Comment on MediaWiki::API->upload() problem
Download Code
Re: MediaWiki::API->upload() problem
by choroba (Abbot) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://928100]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-11-28 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (191 votes), past polls