How to create an issue with an image attached in one operation?

Jan Osmers July 9, 2014

Hi there,

I want to create an issue where the description includes an image tag like !image.png!. The image should be attached to that issue within the create operation. This is to ensure that the image is already there when the create postfunctions will run. E.g. the create notification should render and contain this image.

I tried this two calls.

final Issue issue = this.getIssueManager().createIssueObject(reporter, fields);

// postfunctions will run here
final ChangeItemBean cib = attachmentManager.createAttachment(file, filename, contentType, reporter, issue);

When doing so the issue is created without the attachment. The notification mail say:

"Unable to render embedded object: File (image.png) not found."

That is because the second call to the attachmentManager updates the issue with the image after it is already created.

In inverse order an exception is thrown claiming that the issue where to attach the image does not exists.

final ChangeItemBean cib = attachmentManager.createAttachment(file, filename, contentType, reporter, issue);

// Exception is thrown.

final Issue issue = this.getIssueManager().createIssueObject(reporter, fields);

Can anyone point me to the right direction?


Cheers,

Jan

2 answers

1 accepted

0 votes
Answer accepted
Jan Osmers July 16, 2014

You have to go with IssueService issueService.validateCreate(..), TemporaryAttachmentsMonitor, IssueService.IssueResult. QuickCreateIssue.java give some hints.

0 votes
Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 9, 2014

You could add "Attachments" to your create screen and add a validator on create that requires the attachments field..

Jan Osmers July 10, 2014

I have to use the Java API from Jira to solve my problem. However I tried to create an issue with an attached image over the GUI create screen. This works well and the image is attached within the create operation.

Suggest an answer

Log in or Sign up to answer