Forums

Uploads aren't created correctly via XML-RPC (metaWeblog.newMediaObject) (4 posts)

  1. cbmono
    Member
    Posted 1 year ago #

    Hello!

    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) "http://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 600x400 px.

    Thanks a lot in advance for any answer.

  2. Joseph Scott
    Member
    Posted 1 year ago #

    Any details in the logs that might give a clue as to what happened?

  3. cbmono
    Member
    Posted 1 year ago #

    Now it works. Instead of using:

    $image = array
    (
    	'name' => 'Aara.jpg',
    	'type' => 'image/jpeg',
    	'bits' => new IXR_Base64 (dirname ( __FILE__).'/image.jpg')
    );

    I used:

    $fs = filesize ($dirname ( __FILE__).'/image.jpg');
    $file = fopen ($dirname ( __FILE__).'/image.jpg', 'rb');
    $data = fread ($file, $fs);
    fclose ($file);
    
    $image = array
    (
    	'name' => 'Aara.jpg',
    	'type' => 'image/jpeg',
    	'bits' => new IXR_Base64 ($data)
    );

    Thanks anyway!

  4. Joseph Scott
    Member
    Posted 1 year ago #

    Yeah, that would help :-)

Topic Closed

This topic has been closed to new replies.

About this Topic