The attachments feature is a useful feature in JIRA, and it sometimes helps to manage the attachments on an issue through the JIRA APIs. In this recipe, we will learn how to work with attachments using the JIRA API.
There are three major operations that can be done on attachments: Create, Read, and Delete. We will see each of them in this recipe.
Make sure the attachments are enabled in your JIRA instance. You can do this from Administration|System | Advanced|Attachments, as mentioned at http://confluence.atlassian.com/display/JIRA/Configuring+File+Attachments .
All the operations on the attachments can be performed using the AttachmentManager
API. The AttachmentManager
can be retrieved either by injecting it in the constructor or from the ComponentAccessor
class, as shown:
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();