Recent Topics

1 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:


$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.


    $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 );

2 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.

3 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

4 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


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

should be replaced with


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

François, thank you for your hint :-)


Form is loading...