Mediawiki::API->upload を使用してメディアウィキに画像をアップロードしようとしています。そうするために、私はこのコードを使用しています:
use strict;
use MediaWiki::API;
use DateTime::Format::ISO8601;
use encoding 'utf8';
binmode STDERR, ":utf8";
use URI::Escape;
use warnings;
use MediaWiki::API;
my $url="http://localhost/mediawiki";
my $wiki_login="nguyenki";
my $wiki_passwd="linh";
my $wiki_domain="";
chomp($wiki_login);
chomp($wiki_passwd);
chomp($wiki_domain);
my $mediawiki;
mw_connect_maybe();
# configure the special upload location.
$mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload";
my $name="fl.png"; # Name of fichier to upload
# upload a file to MediaWiki
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);
$mediawiki->upload( { title => $name,
summary => 'This is the summary to go on the Image:file.jpg page',
data => $data } ) || die $mediawiki->{error}->{code} . ': ' . $mediawiki->{error}->{details};
#To login to the wiki page
sub mw_connect_maybe {
if ($mediawiki) {
return;
}
$mediawiki = MediaWiki::API->new;
$mediawiki->{config}->{api_url} = "$url/api.php";
if ($wiki_login) {
if (!$mediawiki->login({
lgname => $wiki_login,
lgpassword => $wiki_passwd,
lgdomain => $wiki_domain,
})) {
print STDERR "Failed to log in mediawiki user \"$wiki_login\" on $url\n";
print STDERR "(error " .
$mediawiki->{error}->{code} . ': ' .
$mediawiki->{error}->{details} . ")\n";
exit 1;
} else {
print STDERR "Logged in with user \"$wiki_login\".\n";
}
}
}
HTTP::Message content must be bytes at /usr/share/perl5/HTTP/Request/Common.pm line 91 修正方法がわかりません。なにか提案を?
感謝。