Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting attachments files during transition

Виталий January 22, 2021

Hi all!

I'm trying to get attaches were attached during transition as a files.

I can get them using 

def attaches = issue.modifiedFields.get(IssueFieldConstants.ATTACHMENT)?.newValue

and i get list of temporary filenames. And i can get them like files using

attaches .each{attach ->
log.warn 'New Attach'
log.warn attach
newAttList.add(new LazyMap ('fileName': attach, 'file':new File(temporaryAttachmentDirectory, attach)))
}

But there are not properly filenames  - only temporary like temp2135062013794563645. So i can't do anything correct with this files.

Otherwise, i can get list of TemporaryWebAttachment objects using 

def temporaryAttachmentUtil = ComponentAccessor.getComponent(TemporaryWebAttachmentManager)
def formToken = ActionContext.getRequest()?.getParameter(IssueFieldConstants.FORM_TOKEN)

def newAttaches = temporaryAttachmentUtil.getTemporaryWebAttachmentsByFormToken(formToken)

But i couldn't find out how can i get File object from TemporaryWebAttachment. It has filename property, but it's only name of file wich was attached, but i can't find it nowere in filesystem. Also i can't attachment from issue via attachment name - only by attachment id. But i can't get attachment id information from TemporaryWebAttachment.

Anybody knows how to get file object from transition attachment? I'll be greatly thankfull. 

1 answer

1 accepted

1 vote
Answer accepted
Виталий January 22, 2021

Just found it by myself.

TemporaryWebAttachment.getStringId() returns exactly temporary attachment name

so i could get File like this:

new File(temporaryAttachmentDirectory,TemporaryWebAttachment.getStringId())

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events