Recently we have integrated the Jira Rest API into a custom support portal product we are developing in house. I am attempting to create a web component that displays comments on an issue and any attachments within the comments as clickable thumbnails that can be downloaded once the user clicks the thumbnail.
Below is my rest call:
I am using renderBody to output the comment as HTML but have ran into an issue.
Here is a sample of the renderBody output which I then display in a div within my component.
"renderedBody": "<p>By default, cards take all the available width in their parent container, but you can use the <tt>width</tt> and <tt>max-width</tt> classes to control take control of the card’s dimensions. So, let’s change the previous example by reducing the width of the card:</p>\n\n<p><span class=\"nobr\"><a href=\"/secure/attachment/12494/12494_Snippet.cs\" title=\"Snippet.cs attached to XER-11\" data-attachment-type=\"file\" data-attachment-name=\"Snippet.cs\" data-media-services-type=\"file\" data-media-services-id=\"aa14ccc7-a4d3-4803-bba3-9353332c7e5e\" rel=\"noreferrer\">Snippet.cs<sup><img class=\"rendericon\" src=\"/images/icons/link_attachment_7.gif\" height=\"7\" width=\"7\" align=\"absmiddle\" alt=\"\" border=\"0\"/></sup></a></span></p>\n",
The problem is it includes the attachment as a link that appears to go no where what does /secure/attachment/12494/12494_Snippet.cs correspond to?
It would be ideal to have a way to return a renderBody without the attachment links then I could handle them myself. Or I will have to find a way to parse out the attachment links from the renderBody output. Is there a way to use renderBody and omit the attachment links?
Hello Nathan and welcome to the Community!
The REST API endpoint you're using will return the comment data, however, it will not return the full path to any attachments as the attachments themselves will be associated with the issue itself. The URL you're seeing returned is the URL to locate the attachment within the issue.
Ideally, you'll need to build an array of any/all comments from there pull the attachments using GET /rest/api/3/attachment/{id} (This won't give you the attachment itself, but will include the URL where the attachment is stored, example:
-->
"created": "2021-05-21T07:17:06.858+0000",
"size": 23123, "mimeType": "image/jpeg",
"content": "https://your-domain.atlassian.net/jira/secure/attachments/10000/picture.jpg",
"thumbnail": "https://your-domain.atlassian.net/jira/secure/thumbnail/10000/picture.jpg" }
<--
From your example above;
/secure/attachment/12494/12494_Snippet.cs
You can see the attachment ID, which in this case is '12494'. You'll use this ID against the endpoint listed above to then get the metadata and from there add the 'content' URL to have the direct path URL to the attachment.
Hope this information proves helpful.
Regards,
Stephen Sifers
I am facing the issue when trying to get attachments using content URI.
I want to get a blob of the attachment and insert the attachment in our system. Please suggest?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Stephen Sifers I tried with your way, but its giving me error that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.