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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 30, 2018 in Confluence

How Manon Soubies-Camy uses Confluence + Trello to organize webinar notes and her knitting stash

@Manon Soubies-Camy is an engineer who has been an avid Atlassian user since 2014. She helps companies of all sizes transform the way they work with the Atlassian stack, including Jira and Confl...

860 views 8 13
Read article

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