Needing a path to convert an Attachment object into a File object

We have upgraded our Jira instance to version 10.3.5.

Previously, we used the com.atlassian.jira.util.AttachmentUtils.getAttachmentFile(Attachment attachment) method to retrieve a File object for a given attachment, which we would then use to copy the file to a local directory for secondary processing.

In Jira 10, AttachmentUtils.getAttachmentFile() has been removed, so we replaced it with ComponentAccessor.getAttachmentManager().getAttachment(attachment.id). Based on the migration recommendations, we are now using com.atlassian.jira.issue.AttachmentManager to retrieve Attachment objects. However, we are unable to determine how to convert attachment object to file object and are receiving the below error:

ERROR org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.atlassian.jira.issue.attachment.Attachment@********' with class 'com.atlassian.jira.issue.attachment.Attachment' to class 'java.io.File'

Or even more simple, does anyone know how to find the filepath of the Attachment object in the Jira 10 api's?

1 Like