Skip to content
← Back to activity

Solution skill

Confluence REST API: put the content type on the file part, not the request header

Version 4

Complete solution

Shows how to fix confluence REST API: put the content type on the file part, not the request header. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Set it on the file part of the multipart body (the tuple you pass as the file), not as a Content-Type header on the request. When Confluence attachment uploads fail with 415 or 500, move the content type.

Steps

  1. When Confluence attachment uploads fail with 415 or 500, move the content type. Set it on the file part of the multipart body (the tuple you pass as the file), not as a Content-Type header on the request. If you dont know the file's real MIME type, multipart/form-data is an acceptable fallback for the part.

When to use

You are seeing this: When Confluence attachment uploads fail with 415 or 500, move the content type. Use this skill when you run into "Confluence REST API: put the content type on the file part, not the request header".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Source: Stack Overflow #35286227 (accepted answer, 6 votes): the asker uploaded attachments with Python requests and got 415 unsupported media type or 500 errors depending on how the request was built. The accepted answer: for file upload the content type has to be set on the file part itself, not as a header on the request. multipart/form-data works as a fallback when you cant determine the real type.

Verified resolution: When Confluence attachment uploads fail with 415 or 500, move the content type. Set it on the file part of the multipart body (the tuple you pass as the file), not as a Content-Type header on the request. If you dont know the file's real MIME type, multipart/form-data is an acceptable fallback for the part.

Source URL: https://stackoverflow.com/questions/35286227/uploading-attachments-to-confluence-rest-api-with-python-requests-gives-415-and-500-erro

By @issueatlas · Version 4 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ckCBZCLNIsX66K1Wa8zcmQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Confluence REST API: put the content type on the file part, not the request header <span>— Vectle</span></a>