I’m uploading images via XML-RPC using metaWeblog.newMediaObject
My code seems to work fine, because after the upload I become as answer something like:
array(3)
{
["file"]=> string(8) "Aara.jpg"
["url"]=> string(66) "https://myblog.com/wp-content/uploads/2010/09/Aara.jpg"
["type"]=> string(10) "image/jpeg"
}
But if I check the uploaded image, it is just a few bytes big and has a size of 0 x 0 pixel. Does anyone knows whats wrong?
This is my code (PHP):
$XmlRpc_result = null;
$XmlRpc_client = new IXR_Client ($data['Blog']['url'].'/xmlrpc.php');
$image = array
(
'name' => 'Aara.jpg',
'type' => 'image/jpeg',
'bits' => new IXR_Base64 (dirname ( __FILE__).'/image.jpg')
);
try
{
$XmlRpc_result = $XmlRpc_client->query
(
'metaWeblog.newMediaObject',
1,
$data['Blog']['wp_user'],
$data['Blog']['wp_pw'],
$image
);
var_dump ($XmlRpc_result);
}
catch (Exception $e)
{
var_dump ( $e->getMessage ());
}
I also tried using the Zend_XmlRpc_Client Class form the Zend Framework, with the same result.
The image I’m uploading is around 80 Kb big and has a size of 600×400 px.
Thanks a lot in advance for any answer.
]]>I am trying to use newMediaObject function to upload a file using Java. In general, this is how my code looks:
XmlRpcClient client = getClient();
Map<Object, Object> fileData = new HashMap<Object, Object>();
fileData.put("name", fileName);
fileData.put("type", type);
fileData.put("bits", fileBytes);
fileData.put("overwrite", Boolean.TRUE);
Object[] params = new Object[]{new Integer(0), username, password, fileData};
Object uploadResult = client.execute("metaWeblog.newMediaObject", params);
Everything works well but one thing. The file gets uploaded and it looks good but the problem is that the “overwrite” part seems to be not working. Any time I run this code, a new file gets uploaded, even though I am always using the same file name. A number gets appended to the file name.
Also, “wpid-” is prepended to the file name for some reason. So if my file name is “image.png”, after executing this, the WordPress has an image uploaded with a name “wpid-image.png”. If I run it again, I get “wpid-image1.png”.
When I set “overwrite” to Boolean.FALSE, it obviously still does not overwrite but this time nothing gets prepended to the file name, so I have “image.png”.
Please let me know if I am doing something incorrect in my code and also please let me know how would an example code look when I want the uploaded file to overwrite the existing file.
]]>I am attempting to upload a new media item using the method
metaWeblog.newMediaObject.
As the rfc for metaweblog requires, I use BASE64 encoding for ‘bits’.
But, when I ask for the file back, it gives the the raw B64 data, not the decoded image file.
But, when I make bits not base64 encoded I get an error.
I looked at the cvs of the code for this part of the system and it seems to assume that BITS is unencoded, and that it accepts only basic text (as allowed by http)
So, what to do?
Cheers, Peter.
]]>Invalid Server Response
The response to the metaWeblog.newMediaObject method received from the weblog server was invalid.
I’ve found a few postings complaining about this error in earlier versions of WordPress, but not with 2.1.3. Can anyone recommend a way for me to troubleshoot this problem? Perhaps someone else is experiencing the same thing?
Thanks!
]]>This is a problem with the line 835:
$success = fwrite($ifp, $bits);
The API-Doc said i must encode the data with base64, but in this line there is no decode.
I’ll fixed the problem with:
$success = fwrite($ifp, base64_decode($bits));
But is this a real bug or is there something i don’t understand?
Thanks
Kelloggz