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

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

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

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

702 views 1 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you