I’m working on my script for uploading images directly from the iOS Markdown text editor app Editorial to WordPress. The current script uses xmlrpc-Wordpress library, but I’m writing my own so the user doesn’t have to install the extra library just to use my script.
When uploading files with xmlrpclib, I got this annoying thing happening. Every time I uploaded an image using xmlrpclib and the function wp.uploadFile the uploaded file got wpid- prepended to the filename of all my uploaded files.
[cce lang=”python”]mediarray = {‘name’:’test.jpg’,
‘type’:’image/jpeg’,
‘bits’:binaryfile,
‘overwrite’:’false’}
xarr = [”, user, password, mediarray]
result = self.server.wp.uploadFile(xarr)[/cc]
In this example, the uploaded image would get the name wpid-test.jpg instead of test.jpg
Solution
After poking around in the xmlrpc.php file on my WordPress server, I finally found a solution to my problem. The wpid- is added for handling conflicting filenames. This should only be happening if overwrite is set to true put for some reason this doesn’t work. Why? I don’t know (or care.) In the the code above, if I just remove the ‘overwrite’:’false’ statement, it works.
[cce lang=”python”]mediarray = {‘name’:’test.jpg’,
‘type’:’image/jpeg’,
‘bits’:binaryfile}
xarr = [”, user, password, mediarray]
result = self.server.wp.uploadFile(xarr)[/cc]
Problem solved. The filename is now named test.jpg, and the the peasants rejoice. just as we want.
Just putting it up here for people searching for the solution to this problem. I couldn’t find any with Google, so maybe this will help others.
Happy Hacking!
Leave a Reply