Skip to main content


Uploading photo using API?


!Friendica Support, I can't figure out how to upload photos to #Friendica using API, I keep getting "Error 400, no media data submitted". Can anyone point me in the right direction?

Attempt in #Python:
r = requests.get(someurl)
encr = base64.b64encode(r.content)
payload = {'media':encr, 'album':'Mobile'}
r = requests.post('https://friends.deko.cloud/api/friendica/photo/create.xml', data=payload, auth=HTTPBasicAuth('user', 'password'))

Attempt in #Bash:
$ base64 /tmp/img.jpg > /tmp/img64.jpg
$ a=$(cat /tmp/img64.jpg)
$ curl -u user:password --data "album=Mobile" --data "media=$a" https://friends.deko.cloud/api/friendica/photo/create.xml

In both cases I get "400, no media submitted" response.
It's because we're expecting a MIME multipart/form-data request as if it had been sent from a file input form. Also we don't base64 decode anything about the image, so I have no idea who ever successfully used that API endpoint with that misleading documentation.
Thank you for the hint, @Hypolite Petovan ! I got it to work.
    myfile = {"media": ("filename", open('/tmp/tmpimg.jpg', "rb"))}
    r = requests.post('https://friends.deko.cloud/api/friendica/photo/create.xml', files=myfile, data={'album':'Mobile'}, auth=HTTPBasicAuth('user', 'password'))
Very good, although the documentation needs a serious update.