Forums

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

How do I POST attachments to Insight objects with JavaScript?

Mathis Hellensberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2019

I am trying to add a file to an Insight object with JavaScript. The POST request is working perfectly fine in Postman but my function returns a HTTP 500 Error :(

function post() { 
var data = new FormData();
data.append("file", "C:\\Users\\mhellensb\\Downloads\\image.png");
data.append("encodedComment", "test");

var xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr
.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}

});

xhr.open("POST", "http://localhost:8081/rest/insight/latest/attachments/object/7");
xhr.setRequestHeader("X-Atlassian-Token", "no-check");
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Authorization", "Basic eW91Omxvb2tMaWtlQW5JZGlvdA==");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events