Getting binary data from attachment files in Jira using Java.

Prasanna Suman October 30, 2013

Hi,

Do you guys know how to read the actual data from an attachment file while using Java api?

Prasanna

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
ArtUrlWWW April 2, 2014

And, for Jira 6.2

String filePath = PathUtils.joinPaths(ComponentAccessor.getAttachmentPathManager().getDefaultAttachmentPath(), issue.getProjectObject().getKey(), issue.getKey(), attachment.getId().toString());
					File file = new File(filePath);
					if (file.exists()) {
						// attachments file exists...
					}

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 21, 2017

Sometimes this can not work due project renaming issues;

I've been using this way to retrieve the attatchment File object when needed. Maybe this method can help you too;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor
import com.atlassian.jira.issue.Issue

File getAttatchmentFile(Issue issue,String attatchmentId){
    return ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor.class).getAttachmentDirectory(issue).listFiles().find({
        File it->
         it.getName().equals(attatchmentId)
    });
}

Regards, Italo Qualisoni

Like Neta Elyakim likes this
1 vote
rambabu patina
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2013
0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2013

Can you please give more context - is this an issue attachment or some other attachment and what you intend to to with this data ?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events