Hi all!
I have a problem with getting file object by attachment of an issue.
I am using Jira 8.6.1.
I have looked similar question and tried all that was written there, but these approaches don't work.
Else I have found AttachmentUtils.class. It is deprecated, but it has getAttachmentFile() method that directly returns File object by attachment. It also hasn't worked. All of my test breaks by exists() method of the File.class (returns 'false' all the time).
Could you help me with resolve this problem?
I have found in what was a mistake. I tried to get file by wrong path. The path in the link of my question isn't universal so didn't work for me.
Hi @Dmitrii
What exactly are you trying to do with the file? You can try this to get the attachments.
def attachments = ComponentAccessor.attachmentManager.getAttachments(issue)
attachments*.getFilesize()
attachments*.getFilename()
Let me know if this helps.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need file to will write in my zip archive. But I still can't extract file from the attachment.
Zip archive will contain all attachments of the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Approach 1
String filePath = PathUtils.joinPaths(ComponentAccessor.getAttachmentPathManager().getDefaultAttachmentPath(), issue.getProjectObject().getKey(), issue.getKey(), attachment.getId().toString());
File file = new File(filePath);
Approach 2
File file = AttachmentUtils.getAttachmentFile(attachment)
All of these approaches return that the file doesn't exist
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.