File upload via REST API?

Just in case anyone’s wondering how to upload files using Python Requests, something like this should work…

params = {
    'key_identity': key_identity,
    'key_credential': key_credential
}

data = {
    "o:ingester": "upload", 
    "file_index": "0", 
    "o:item": {"o:id": "13"}
}

files = [
     ('data', (None, json.dumps(data), 'application/json')),
     ('file[0]', ('7288020-p15.jpg', open('7288020-p15.jpg', 'rb'), 'image/jpg'))
]

response = requests.post('http://example.com/api/media', params=params, files=files)

Took me a while to figure out how to combine the JSON and image files.