I couldn't find anything else in the forums, but I'm trying to upload an image to a Wordpress site via xmlrpclib. I was able to do it with an image hosted online using this code:
def new_image(url, post_id = None):
import urllib2
from re import findall
raw = urllib2.urlopen(url)
image = raw.read()
content = {}
content['bits'] = xmlrpclib.Binary(image)
content['name'] = findall('[^\/]+?$',url)[0]
content['type'] = 'image/jpeg'
if post_id is not None:
content['post_id'] = post_id
img = server.wp.uploadFile(1,username,password,content)
return img
(server, username and password are defined earlier)
I'm trying to do the same thing with an image chosen from my camera roll (I go through my company's Instagram feed and upload it for a weekly blog post, but sometimes I have a 4:3 version I want to use instead). To get content['bits'] I'm using:
import photos
image = photos.pick_image(False, True, False)
image[0].verify()
content = {}
content['bits'] = xmlrpclib.Binary(image[0].tostring())
This... works, in that an object is returned, but the image doesn't actually upload. See this example.
File and I/O stuff are what I hate most about coding, and I don't really understand all the components, so maybe (hopefully) there's something easy I'm missing.