upload.rb
require 'xmlrpc/client'
@host = 'example.com'
@rpcPath = '/xmlrpc.php'
@user = 'user'
@pass = 'pass'
@file = './test.jpg'
server = XMLRPC::Client.new(@host, @rpcPath)
id = '1' #ライブラリに入れたい記事のPostId
fileName = File.basename(@file)
open(fileName, 'wb') do |file|
open(@file) do |data|
file.write(data.read)
end
end
base64 = XMLRPC::Base64.new(File.read(fileName))
fileHash = {
:name => 'uptest.jpg'
:bits => base64
}
server.call("metaWeblog.newMediaObject",id,@user,@pass,fileHash )