Uploading attachments via REST API using axios Edited

I'm having a lot of trouble uploading an attachment to a created issue using the REST API. Currently I'm getting a 415 - "unsupported media type" error. 

I would really appriciate some help with this. Thanks! 

 

let actionData=new FormData();
actionData.append('file', files[0]);
actionData.append('comment', "foobar");
actionData.append('minorEdit', "true");
axios({
      method: 'POST',
      url: jiraApiUrl+'/issue/'+issueID+'/attachments',
      headers: {
             'X-Atlassian-Token': 'nocheck',
      },
data: actionData,
}).then(response => {
              //if (!cb) return { error: 'No callback' };
             console.log('response-2', response);
             return ;//cb(response);
})
.catch((err) => console.log('errorTest - files', err));

1 answer

0 votes

I'm not sure about using axios, but from looking at other instances with this error such as

How to change the mediatype of an attachment via REST API

REST API error 415 unsupported media type

It seems like this might be a problem with a lack of a content type paramenter.   I think you might need to clarify the request by adding a

'Content-Type: application/json'

somehow to this REST.   But I also think you will need to modify the

'X-Atlassian-Token': 'nocheck'

to be

'X-Atlassian-Token: nocheck'

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,221 views 5 10
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