Discourse API Uploads

This worked for me:

r = requests.post(f'{rooturl}/uploads.json',
                  files = {'files[]': (file, open(file, 'rb'), 'image/png')},
                  data={'type':'image'},
                  headers={
                      "Api-Username" : sys.argv[1],
                      "Api-Key" : sys.argv[2],
                  })

Probably, content-type': 'multipart/form-data' should be omitted so the requests library can figure out what to.

4 Likes