Attach a file to jira from Java API using a stream

I'm trying to add attachment from input stream or byte array .



I have the following code:


Blob blob = rset.getBlob(12);

int blobLength = (int) blob.length();
byte[] blobAsBytes = blob.getBytes(1, blobLength);;
String folder ="/home/atlassian/application-data/SBMAttachments/";
File tempFile = new File(folder+filePrefix + fileName);

FileOutputStream fos = new FileOutputStream(tempFile);
addAttachmentToJira(tempFile,issue, fileName,user);
public static boolean addAttachmentToJira(File file,Issue issue,String filename,ApplicationUser user) throws Exception{
MimeManager mm = new MimeManager(new FileInputStream(file));

AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();
CreateAttachmentParamsBean.Builder builder = new CreateAttachmentParamsBean.Builder();
CreateAttachmentParamsBean bean =;
com.atlassian.fugue.Either<AttachmentError,ChangeItemBean> result = attachmentManager.tryCreateAttachment(bean);
if (result.isLeft()) {
AttachmentError attachmentError = (AttachmentError) result.left().get();
//LOG.error("AttachmentError '" + attachmentError.getLogMessage());
} else {
ChangeItemBean changeItemBean = (ChangeItemBean) result.right().get();
return true;


My idea is to add the attachment without saving the file (to save time).

Is there a way to add the attachment from input stream ?


0 answers

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...

243 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