Hi, I'm trying to upload an image to the mediawiki using the Mediawiki::API->upload. To do so, i'm using this code:
*# Open a file whose name is $name = "1.jpg"* * open (my $toi,$name) or die "can't open UTF-8 encoded filename: $!"; binmode $toi; my ($buffer, $data); while (my $n=read($toi, $buffer, 65536)) { $data .= $buffer; print STDERR " $n bytes read \n"; } close($toi); * *#upload file my $kq= $mediawiki->upload( { title => $name, summary => 'upload file', data => $data } ) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};*
And it generated an error: *HTTP::Message content must be bytes at /usr/share/perl5/HTTP/Request/Common.pm line 91* I don't know how to correct it. Any suggestion?
Thank.
On Sun, May 27, 2012 at 2:23 AM, nguyenkim thuat kimthuatnguyenensimagfr@gmail.com wrote:
And it generated an error: HTTP::Message content must be bytes at /usr/share/perl5/HTTP/Request/Common.pm line 91 I don't know how to correct it. Any suggestion?
This looks like a problem with the library that you're using (or you using the library incorrectly), not a problem with the MediaWiki API itself. That said, may be other people on this list who have used this library before and can help you with it.
Roan
All the library that i'm using:
*use strict; use MediaWiki::API; use DateTime::Format::ISO8601; use encoding 'utf8'; * i tried to update the version of perl and LWP like the suggestions that i found in the internet but it doesn't work. Hope someone can help me.
Thank.
On Sun, May 27, 2012 at 10:35 PM, Roan Kattouw roan.kattouw@gmail.comwrote:
On Sun, May 27, 2012 at 2:23 AM, nguyenkim thuat kimthuatnguyenensimagfr@gmail.com wrote:
And it generated an error: HTTP::Message content must be bytes
at
/usr/share/perl5/HTTP/Request/Common.pm line 91 I don't know how to correct it. Any suggestion?
This looks like a problem with the library that you're using (or you using the library incorrectly), not a problem with the MediaWiki API itself. That said, may be other people on this list who have used this library before and can help you with it.
Roan
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Could be a bug in the library. If you email me a standalone program that produces the issue, I can try and reproduce it and help you.
note that if your mediawiki is >= v1.16 then you should not use the "upload" function, but rather the "edit" call - or directly via the "api" call. However the upload call should check your mediawiki version, and use the api directly if it can - but I could have made a mistake.
see: http://search.cpan.org/~exobuzz/MediaWiki-API-0.39/lib/MediaWiki/API.pm#Medi...
which you can use and it will handle the tokens for you for things like file upload
something like
$title = 'somefile.jpg'; $mw->edit( { action => 'upload', filename => $title, comment => 'uploaded an image', file => [ $title ], ignorewarnings => 1, bot => 1 } );
also worth noting there is the http://search.cpan.org/~lifeguard/MediaWiki-Bot-3.005002/ extension, that is a higher level interface and provides simpler function calls - might be useful for you.
Best Regards
Jools
mediawiki-api@lists.wikimedia.org