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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mogavenasan,
This would probably explain the issue we had. Thank you for letting me know.
Regards,
Irena
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.