I am trying to upload my png image to atlassian Confluence and here my approach is converting the adoc->html->importing it to confluence.
everything is working correctly when I am converting to html and that time also my image is visible. Also in my confluence attachments I can see the image but I am unable to see the same image on my confluence page.
I am unable to understand the issue.
code:
def upload_image_to_confluence(page_id, image_path):
"""Upload an image as an attachment to a Confluence page"""
filename = os.path.basename(image_path)
if not os.path.exists(image_path):
return False
file_size = os.path.getsize(image_path)
if file_size == 0:
return False
mime_type, _ = mimetypes.guess_type(image_path)
if not mime_type:
mime_type = 'application/octet-stream'
try:
# Check if exists
existing = check_attachment_exists(page_id, filename)
if existing:
url = f"{CONFLUENCE_URL}/rest/api/content/{page_id}/child/attachment/{existing['id']}/data"
else:
url = f"{CONFLUENCE_URL}/rest/api/content/{page_id}/child/attachment"
with open(image_path, 'rb') as img_file:
files = {'file': (filename, img_file, mime_type)}
response = requests.post(
url,
auth=HTTPBasicAuth(EMAIL, API_TOKEN),
files=files,
headers={'X-Atlassian-Token': 'no-check'}
)
return response.status_code in [200, 201]
except Exception as e:
print(f" ❌ Exception: {str(e)}")
return False
You’re experiencing an issue where your PNG image successfully uploads to Confluence and appears in the page attachments, but does not display on the actual Confluence page after you import your HTML. The upload process itself works fine, but the image reference inside your HTML is not pointing to the correct Confluence attachment path.
When you convert your .adoc → .html → and then import that HTML into Confluence, the image src attributes in the HTML still reference local paths (for example, src="images/diagram.png"). However, Confluence expects image references to use its internal attachment download URLs, formatted like this:
/download/attachments/{page_id}/{filename}?version={version_number}
If your HTML doesn’t use this structure, the image won’t appear even though it’s attached to the page.
To fix this, you need to upload the image (which you already do correctly), then retrieve the attachment’s download link from Confluence, and finally replace the image paths in your HTML with the proper download URLs before updating the page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.