In this recipe, we will see how to add attachments on an issue via REST and browse existing attachments.
Create a JIRA REST client as mentioned in the Writing a Java client for the REST API recipe. Make sure attachments are enabled on the JIRA instance by checking at Administration | System | Advanced... | Attachments.
There are three different methods exposed by JRJC to add attachments on to an issue. The following are the three options and how they are used.
Create an
InputStream
object from the file path:InputStream in = new FileInputStream("/Users/jobinkk/Desktop/test.txt");
Get the issue to attach the file. You can use the
IssueRestClient
object as explained previously.final Promise<Issue> issue = jiraRestClient.getIssueClient().getIssue(key); Issue browsedIssue = issue.get();
Get the attachment URI from the issue.
URI attachmentURI = browsedIssue.getAttachmentsUri();
jiraRestClient...