Opened 11 months ago

Closed 11 months ago

Last modified 4 months ago

#20984 closed defect (bug) (invalid)

XMLRPC: wp.uploadFile missing base64_decode

Reported by: fishc4ke Owned by:
Priority: normal Milestone:
Component: XML-RPC Version: 3.4
Severity: normal Keywords:
Cc: maxcutler

Description

Uploading images via wp.uploadFile results in a broken image as the base64 bits are not decoded again.

Looking at the code, the file is written to disk by the function wp_upload_bits in functions.php.

A fix would be to alter line 1615 of functions.php:

@fwrite( $ifp, $bits );

to

@fwrite( $ifp, base64_decode($bits) );

However, I have not tested to see if this would break any other functionality.

Change History (7)

  • Cc maxcutler added

I am unable to reproduce this, can you please provide more details?

$bits is actually binary data by that point, since IXR_Message will call base64_decode before mw_newMediaObject (wp.uploadFile) is ever called. See L303 of wp-includes/class-IXR.php.

The codex page states that bits' needs to be a base64-encoded, so I am simply opening the file and base64-encoding its contents (via Python 2.7.3) before uploading.

Can you supply the exact XML-RPC request you are sending to WordPress? If you are using the base64 value type as defined in the spec, then it should be doing the Right Thing.

If you are using Python's xmlrpclib, you can take a look at my python wrapper library to see the correct way to handle binary data.

I've had another look at my code, found the issue. Bug in my code and as I was looking through the WP code I jumped to conclusions. tl;dr I'm an idiot.

  • Resolution set to invalid
  • Status changed from new to closed
  • Milestone Awaiting Review deleted

#23137 was marked as a duplicate.

Note: See TracTickets for help on using tickets.