Skip to content

Commit 30cedd6

Browse files
authored
Fix attach_content on Confluence Server with an existing attachement (#1679)
On-Premise Confluence Server doesn't support PUT like the Cloud version. We have to use the old code path from 4.x, where we use POST on a path below the child. Fixes #1677 Follow-Up to #1666
1 parent 5fd9869 commit 30cedd6

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

atlassian/confluence/server/__init__.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,15 +1436,26 @@ def attach_content(
14361436
pass
14371437

14381438
if existing_attachment:
1439-
# Update existing attachment using PUT on the specific attachment ID
1439+
# Update existing attachment on the specific attachment ID
14401440
attachment_id = existing_attachment["id"]
1441-
update_path = f"rest/api/content/{attachment_id}"
1442-
response = self.put(
1443-
path=update_path,
1444-
data=data,
1445-
headers=headers,
1446-
files={"file": (name, content, content_type)},
1447-
)
1441+
if self.api_version == "1.0":
1442+
# older API versions use POST on data path below the child
1443+
update_path = f"{path}/{attachment_id}/data"
1444+
response = self.post(
1445+
path=update_path,
1446+
data=data,
1447+
headers=headers,
1448+
files={"file": (name, content, content_type)},
1449+
)
1450+
else:
1451+
# newer API versions use PUT on a path derived from the attachment ID directly
1452+
update_path = f"rest/api/content/{attachment_id}"
1453+
response = self.put(
1454+
path=update_path,
1455+
data=data,
1456+
headers=headers,
1457+
files={"file": (name, content, content_type)},
1458+
)
14481459
else:
14491460
# Create new attachment using POST
14501461
response = self.post(

0 commit comments

Comments
 (0)