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 vote

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
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
Published Thursday in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

403 views 2 4
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