How to change mediaType of attachment with REST API?

Here's what I'm trying:

curl -n -Ss -X PUT -H 'X-Atlassian-Token: nocheck' '-d{"metadata": {"mediaType": "image/svg+xml" }' https://xxx.atlassian.net/wiki/rest/api/content/26509481/child/attachment/att26869829

This yields: HTTP Status 415 - Unsupported Media Type

Both the PUT /rest/api/content/{id}/child/attachment/{attachmentId} (after uploading) and POST /rest/api/content/{id}/child/attachment/{attachmentId}/data (while uploading) endpoints claim to be able to update the media type (although it confusingly switches between the media-type and content-type terminology), but neither give any indication of how to do so.

Another method I've tried is setting the Content-Type HTTP header to "image/svg+xml", but this is rejected with an "invalid media type" error.

I can update using the UI just fine.

I also tried the REST API Browser, but like all useful parts of Confluence, it's not available on a cloud install >:[

 

 

 

1 answer

1 accepted

Accepted Answer
0 votes

The error message you are getting is because you are not setting the Content Type header for the PUT request to application/json. You need to add -H 'Content-Type: application/json' to your curl request. I've included an example below. 

curl -n -u admin:admin -X PUT -H 'Content-Type: application/json' -H 'X-Atlassian-Token: nocheck' -d '{"id":"att917507", "version":{"number":1}, "metadata": {"mediaType": "image/svg+xml" }}' http://localhost:1990/confluence/rest/api/content/98310/child/attachment/att917507

 

 

That's probably it. I can't test any more, but have a checkmark.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Confluence

What are your project planning tips?

Hello Community,  Jessica here from the Confluence product marketing team! Today I wanted to get your takes on project planning –– what works, what doesn’t, how do you know if you’re doing it r...

315 views 1 4
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you