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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Asked May 24, 2018 in Confluence

What are the resources that you use to learn more about Atlassian Products?

I am gathering information about resources available for Atlassian product knowledge transferring for a presentation in our local Atlassian User Group. I want to group them in four categories From ...

603 views 18 16
View question

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