The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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