Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

In Python, how do I set request parameters in POST call for uploading images to a page?

antony terrence March 21, 2019

I am trying to use Confluence REST APIs to make a POST call to upload images. In postman, I get error that says "unsupported media type." Can you tell me what I am doing wrong in the following python request:

import requests
headers = {
'X-Atlassian-Token': 'no-check',
}
files = {
'file_0': ('branch_strategy_2.jpg', open('branch_strategy_2.jpg', 'rb')),
}
url = '<baseURL>/rest/api/content/<pageID>/child/attachment'
file = "c_branch_strategy_2.jpg"
response = requests.post(url, headers=headers, files=files, auth=('uid', 'pwd'))
print(response.json)

1 answer

1 vote
antony terrence March 21, 2019

I found my answer, thanks to this post: https://community.atlassian.com/t5/Confluence-questions/How-to-post-attachments-to-confluence-page/qaq-p/214853

import requests
headers = {
'X-Atlassian-Token': 'no-check',
}
data = {"comment":"this is my file"}

files = {'file': open('branch_strategy_2.jpg', 'rb')}
url = '<baseURL>/rest/api/content/<pageID>/child/attachment'
r = requests.post(url, data=data, auth=('uid', 'pwd'), files=files, headers=headers)
print(r.status_code)
print(r.text)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events