Recent Topics

[NOT A BUG] XML-RPC metaWeblog.newMediaObject

Started by on Feb 07, 2008 – Contents updated: Feb 07, 2008

Feb 07, 2008 10:23    

I am not sure whether it is a bug or my misunderstanding
I try to post binary files using metaWeblog.newMediaObject with b2evolution 2.4.0 "Venetian".

According to the specifications "bits" should be base64-encoded, something like that:

Code

$fs = filesize($tmp_name);
$file = fopen($tmp_name, 'rb');
$data = fread($file, $fs);
$object = chunk_split(base64_encode($data));
fclose($file);
 
$request = new XML_RPC_Message('metaWeblog.newMediaObject', array(
                                 new XML_RPC_Value($blog_id),
                                 new XML_RPC_Value($username),
                                 new XML_RPC_Value($password),
                                 new XML_RPC_Value(array(
                                             'name' => new XML_RPC_Value($name),
                                             'type' => new XML_RPC_Value($type),
                                             'bits' => new XML_RPC_Value($object, 'base64')
                                             ), 'struct')
                                 ));

If this is correct, then the decoding in inc/xmlrpc/apis/_metaweblog.api.php is done incorrectly, the 'bits' are saved still base64-encoded into the media directory (and useless of course!)

I modified the code (see the decoding stuff below, inside // MVE comments) and it does the job. Still I am not 100% sure that I understood all right.

Code

$data = $contentstruct['bits'];
 
    // MVE 20080207 - isn't it supposed to be base64-encoded?
    $data = base64_decode($data);
 
    if ($data === FALSE) {
        return new xmlrpcresp(0, $xmlrpcerruser+9, // user error 9
                 'Cannot decode bits');
    }
    // MVE EOF
 
    $type = $contentstruct['type'];
    logIO( 'Received MIME type: '.$type );

Feb 08, 2008 23:37

When used with popular desktop blogging tools like ScribeFire , Windows Live Publisher and Ecto, the images seem to be saved correctly and display correctly. So I assume the implementation is correct. Or at least it's compatible with what the industry wants if not the spec.

Feb 15, 2008 09:22

Hello Fran├žois

I am in doubt... All blogging tools are closed-source, therefore I have no idea what do they do internally and how do they post.

And the codelet I posted is found on Internet as a XML-RPC example. It uses base64 encoding and is _not_ accepted by b2evolution.

Do you have any really working test for testing b2evolution? particulary to upload binary files using metaWeblog.newMediaObject?

Best regards,
Maxim

Feb 16, 2008 14:18

OK, I found a bug in my own code (of course!)
b2Evolution contains no bug, indeed.

There is no need to base64_encode the file content before using it inside a XML_RPC_Value:

My code

Code

$data = fread($file, $fs);
$object = chunk_split(base64_encode($data));
fclose($file);

should be replaced with

Code

$data = fread($file, $fs);
$object = $data;
fclose($file);

Fran├žois, thank you for your hint :-)


Form is loading...

powered by b2evolution – This forum is powered by b2evolution CMS, a complete engine for your website.