-
-
Save cxzero/9effd5f8b1ad42d6669baf3283306aa7 to your computer and use it in GitHub Desktop.
How to upload a file to a WordPress site via the XML-RPC API. Pretty easy, no? The attachment page if you want a html wrapper to present the file can be found at the following URL: http://yoursite.com/?attachment_id=722 (I left the ID the successful response in as an example)
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
<?xml version='1.0' encoding='utf-8'?> | |
<methodCall> | |
<methodName>wp.uploadFile</methodName> | |
<params> | |
<param><value><string>1</string></value></param> | |
<param><value><string>username</string></value></param> | |
<param><value><string>password</string></value></param> | |
<param> | |
<value> | |
<struct> | |
<member> | |
<name>name</name> | |
<value><string>filename.jpg</string></value> | |
</member> | |
<member> | |
<name>type</name> | |
<value><string>mime/type</string></value> | |
</member> | |
<member> | |
<name>bits</name> | |
<value><base64><![CDATA[---base64-encoded-data---]]></base64></value> | |
</member> | |
</struct> | |
</value> | |
</param> | |
</params> | |
</methodCall> |
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
curl --data @command.xml http://yoursite.com/xmlrpc.php |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<methodResponse> | |
<fault> | |
<value> | |
<struct> | |
<member> | |
<name>faultCode</name> | |
<value><int>403</int></value> | |
</member> | |
<member> | |
<name>faultString</name> | |
<value><string>Incorrect username or password.</string></value> | |
</member> | |
</struct> | |
</value> | |
</fault> | |
</methodResponse> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<methodResponse> | |
<params> | |
<param> | |
<value> | |
<struct> | |
<member> | |
<name>id</name> | |
<value><string>722</string></value> | |
</member> | |
<member> | |
<name>file</name> | |
<value><string>filename.jpg</string></value> | |
</member> | |
<member> | |
<name>url</name> | |
<value><string>http://yoursite.com/wp-content/uploads/2013/05/filename.jpg</string></value> | |
</member> | |
<member> | |
<name>type</name> | |
<value><string>mime/type</string></value> | |
</member> | |
</struct> | |
</value> | |
</param> | |
</params> | |
</methodResponse> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment