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