Download attachment with atlassian-connect-express sample


I am trying to download a Jira issue attachment using the atlassian-connect-express sample (JWT security).  The attachment is received successfully but in string format and not binary.

Trying to save jpeg attachment to file system ends up with the jpeg being corrupted and trying to do a base64 encoding crashes due to invalid characters.

Downloding the jpeg attachment url directly from browser works fine... I think he root cause is that the jpeg is coming as a string. How do I download in binary base64?


Function code below as well as two attachments. I am stuck so all help is very much appreciated...

app.get('/img', addon.checkValidToken(), function(req, res) { var httpClient = addon.httpClient(req);
httpClient.get({ "headers": { "Content-Type": "image/jpeg", "Accept": "image/jpeg" }, "url": "" //"url": "rest/api/2/attachment/10002"
}, function(err, response, body) { if (err) { console.log(response.statusCode + ": " + err); res.send("Error: " + response.statusCode + ": " + err); } else { console.log('error:', err); // Print the error if one occurred console.log('statusCode:', response && response.statusCode); // Print the response status code
//Enabling this one crash. Probably because not valid characters - only characters in the range from U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF //var encodedData = base64.encode(body);
fs.writeFile("tmp/test.jpeg", body, function(err) { if (err) { console.log(err); } else { console.log("The file was saved!"); res.send(body); } });

} } ); });








1 answer

This widget could not be displayed.

Hi @Johan Brodin,


I suggest posting this to our developer community forum.



Anne Calantog

ok Thx for the replay!

Did not realize that I had posted it to the wrong forum...

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

94 views 0 3
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