It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to construct link to an attachment Edited

Hana_Kučerová Community Leader Dec 19, 2019

Hello,

I'm trying to create a comment in issue, which contains link to some specific attachment from another issue (let's assume it has id = 10001).

Below is the code, which I use to get the attachment and construct the link.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.Attachment

ApplicationProperties applicationProperties = ComponentAccessor.getApplicationProperties()
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()

String baseUrl = applicationProperties.getString(APKeys.JIRA_BASEURL)
Long attachmentId = 10001

Attachment attachment = attachmentManager.getAttachment(attachmentId)
String attachmentUrl = "$baseUrl/secure/attachment/${attachment.id}/${URLEncoder.encode(attachment.filename, 'UTF-8')}"

Everything works fine for me, but I've been wondering, if there is a better way to create the attachment's url (variable attachmentUrl). This is the best solution, I've been able to find, but it seems to me, that there should be some method, to which I provide attachment id and which returns constructed link. Am I missing something?

Thank you very much!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you