8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WordPressにXML-RPCを使ってメディア(画像・動画等)を追加する

Posted at
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 )
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?