Download attachment with atlassian-connect-express sample

Hi,

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": "https://xxxxx.atlassian.net/secure/attachment/10002/download.jpg" //"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); } });

} } ); });

 

Regards
Johan

 

Capture1.PNGCapture2.PNG

 

 

 

1 answer

0 vote

Hi @Johan Brodin,

 

I suggest posting this to our developer community forum.

 

Cheers,

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,311 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot