Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change mediaType of attachment with REST API?

Nick Irvine
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 22, 2015

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 >:[

 

 

 

2 answers

1 accepted

0 votes
Answer accepted
Neil Russell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 25, 2016

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

 

 

Nick Irvine
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 1, 2016

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

1 vote
LostInMadness Forever December 2, 2019

here is my code to upload an image.. i got 415 status, meaning bad content-type

of course, i longon first using "auth/1/session"

 

here to upload..

file = "C:\Users\User\Documents\file.jpg"

oRequest.Open("POST", jiraURL)
oRequest.SetRequestHeader("X-Atlassian-Token", "no-check")

oRequest.SetRequestHeader("Content-Disposition", "form-data; name=""file""; filename=""file.jpg""")
oRequest.SetRequestHeader("Content-Type", "image/jpeg; boundary=WebKitFormBoundaryE19zNvXGzXaLvS5C")

oRequest.Send(file)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events