Created
February 19, 2011 07:54
-
-
Save comewalk/834911 to your computer and use it in GitHub Desktop.
upload a jpeg file to livedoor blog via atompub. but I'm getting 400 though. hmm :(
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=head1 NAME | |
upload2livedoor - upload a jpeg file to livedoor blog via atompub | |
=head1 SYNOPSIS | |
upload2livedoor.pl [userid] [apikey] [filename] | |
=cut | |
use strict; | |
use warnings; | |
use feature qw/say/; | |
use Data::Dumper; | |
use FileHandle; | |
use XML::Atom::Client; | |
use XML::Atom::Content; | |
use XML::Atom::Entry; | |
my ($userid, $apikey, $filename) = @ARGV; | |
die 'upload2livedoor.pl [userid] [apikey] [filename]' if scalar @ARGV != 3; | |
my $client = XML::Atom::Client->new; | |
$client->username($userid); | |
$client->password($apikey); | |
local $/; | |
my $fh = FileHandle->new($filename); | |
my $image = $fh->getline; | |
$fh->close; | |
my $content = XML::Atom::Content->new; | |
$content->body($image); | |
$content->type('image/jpeg'); | |
my $entry = XML::Atom::Entry->new; | |
$entry->content($content); | |
my $editURI = $client->createEntry("http://livedoor.blogcms.jp/atom/blog/$userid/image", $entry); | |
say Dumper($client); | |
say $editURI ? $editURI : $client->errstr; | |
say 'Done!'; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment