Forums

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

Attaching image to Jira issue via Cloud REST API breaks the image

Irena Shemesh October 9, 2018

Hello,

Our ACE add-on grubs a file from a remote location via HTTP request and attaches the file to a Jira issue using Jira Cloud REST API (v2). It works fine with text based files, e.g. json, csv. When attaching an image (jpeg, png), operation finishes successfully, file is attached to the issue, but file size is almost twice of the original file size and image is not displayed - broken.

 

Here is the code, using request npm package:

let getFileOptions = { 
method: 'GET',
uri: attachment.fileUrl,
headers: {
'Content-Type': attachment.mimetype
}
};

request(getFileOptions, (err, response, data) => {
if (err) {
<fail>
}

addonParams.http.asUser(userKey).post({
url: <image url>,
headers: {
'X-Atlassian-Token': 'nocheck' },
multipartFormData: {

file: [data, {
filename: attachment.name,
contentType: attachment.mimetype
}]
}

},
function (err, httpResponse, body) {
if (err) {
<
fail>
}


<
success>
});
});  

Any ideas why image files are broken after attached? 

 

Thanks,

Irena 

1 answer

1 accepted

0 votes
Answer accepted
Moga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 16, 2018

Hi Irena,

From the JIRA Cloud REST API; Add attachment - the Content-Type is multipart/form-data. In your code, you are defining something different. Just a suspicion, you might want to try this Content-Type and see how it goes.

Cheers,
Mogavenasan

Irena Shemesh October 16, 2018

Hi Mogavenasan,

Thank you for your answer. I tried specifying Content-Type multipart/form-data in the post request header, also tried removing the file content type. Unfortunately, with the same result. The only solution to work for us was to read the file from remote locations and save the file first, then upload it. 

Thanks anyway.

Regards

Irena

Moga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 16, 2018

Hey Irena,

Now that you have mentioned remote location, I realized something. You are providing the image URL - this is not possible. If you go directly to JIRA and try to add an attachment, we can only add files from physical form only. Unless you have mounted the remote locations hard drive on the machine - then it's a different story.

Regards,
Mogavenasan

Irena Shemesh October 16, 2018

Hi Mogavenasan,

This would probably explain the issue we had. Thank you for letting me know.

Regards,

Irena

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events