It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Updating binary data of attachment via REST API produces blank version Edited

Good Day: I have created a Python3 script to manipulate subpages and attachments on a Confluence system.  The script can successfully list, create, and delete subpages, and can successfully list, upload, and delete attachments.  However, when the script attempts to update the binary data of an attachment, a revision is made but the content of the revision is blank.  (The original version retains the original content.)

When the revision is made via the script, the operation shows a status code of 200, and the process appears to work, but the content is blank nevertheless.

Here is the relevant code block:

url = 'https://<host>/rest/api/content/' + contentID + '/child/attachment/' + attachmentID + '/data'

headers = {
'Accept': 'application/json',
'X-Atlassian-Token': 'nocheck'


files = {'file': open(tempfile_path + '/' + file_to_copy, 'rb')}

r = requests.post(url, files = files, headers = headers, auth = (username, password))

When I use a browser to upload the revised file, the updated content appears on the revision.

Any assistance would be appreciated.  Please bear with me, I am quite new to Confluence.

Thank you. 

1 answer

1 accepted

0 votes
Answer accepted

After further testing and troubleshooting, a coding logic error in the script was discovered.

The following line:

files = {'file': open(tempfile_path + '/' + file_to_copy, 'rb')}

was not being called as part of the update section; instead, the variable "files" was being referred in the call to upload the file.  Since the initial call to the "files" line completed and pointed to the end of the file, the variable was blank and therefore the script updated the post with a "blank" attachment.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

8,368 views 6 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you