JIRA cloud plugin not able to attach a text file as an attachment Edited

I am trying to attach a text file to Jira cloud instance via Jira Plugin. I am creating blog file in the javascript and making a REST call to the server.

The call is going through successfully but it is returning empty json array in response. When I refresh the Jira issue page in the browser then I do not see any attachment.

Please find the JavaScript code snippet I am using below:

attachToTicket("Hello there", "hello.txt");

function attchToTicket(fileContent, fileName) {

var formData = makeFile(fileContent, fileName);
AP.require('request', function (request) {
request({
url: '/rest/api/2/issue/TEST-2/attachments',
data: formData,
type: 'POST',
dataType: 'application/json',
contentType: 'multipart/form-data',
/* Keeping or removing below lines does not help either
processData: false,
cache: false,
*/

success: function (response) {
response = JSON.parse(response);console.log(response);
},

error: function () {
console.log("error: " + arguments);
}
});
});
}

function makeFile(content, fileName) {
var theBlob = new Blob([content], {
type: 'text/plain; charset="UTF-8"'
});

var formData = new FormData();

formData.append("file", theBlob, fileName);
return formData;
}

 

In my chrome console it shows 200 OK. Any hint on this will be of great help. 

Thank you!

 

0 answers

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 May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

840 views 2 9
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