How to get a attachment in binary with atlassian-connect-express (coming as string...)


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.

Downloading the jpeg attachment url directly from browser works fine… Getting it in a binary format should be a easy thing but I am stuck so any help is highly appreciated…

Below is the function used

app.get('/img', addon.checkValidToken(), function (req, res) {

    var httpClient = addon.httpClient(req);

        "headers": { "Content-Type": "image/jpeg", "Accept": "image/jpeg" },
        "url": ""
    }, function (err, response, body) {

        if (err) {
            console.log(response.statusCode + ": " + err);
            res.send("Error: " + response.statusCode + ": " + err);
        } else {
            console.log('error:', err);

            //Enabling below line  crash due to invalid characters should be in range from U+0000 to U+00FF 
            //var encodedData = base64.encode(body);

            //The file is saved however it is corrupted.... The received body is a string...
            fs.writeFile("tmp/test.jpeg", body, function (err) {
                if (err) {
                } else {
                    console.log("The file was saved!");

Did you ever find a solution to this? I’ve got the same issue.

Anyone solved this problem? I’m encountering them right now.