I wish to programatically set an attachment to a newly created issue equal to the attachment that already exists on another issue. Any suggestion would be greatly appreciated!
Community moderators have prevented the ability to post new answers.
try with the following to copy attachments from other issue
AttachmentManager attchMgr = ComponentAccessor.getAttachmentManager(); AttachmentPathManager pathManager = ComponentAccessor.getAttachmentPathManager(); List<Attachment> attchments = attchMgr.getAttachments(sourceIssue); if (!attchments.isEmpty()) { for (Attachment attachment : attchments) { String filePath = PathUtils.joinPaths(pathManager.getAttachmentPath(), sourceIssue.getProjectObject().getKey(), sourceIssue.getKey(), attachment.getId().toString()); File atFile = new File(filePath); if (atFile.exists()) { try { if (atFile.canRead()) { attchMgr.createAttachmentCopySourceFile(atFile, attachment.getFilename(),attachment.getMimetype(), attachment.getAuthor(), issue, null, attachment.getCreated()); } } catch (SecurityException se) { System.out.println("Could not read attachment file. Not copying. (${se.message})"); } catch (AttachmentException e) { e.printStackTrace(); } } else { System.out.println("Attachment file does not exist where it should. Not copying."); } } }
ts from one issue to another
Rambanam you're a life saver!!! It works perfectly! I cant thank you enough =D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
glad to hear it worked!!
cheers...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
"createAttachmentCopySourceFile" method deprecated since jira 6.0 and the new method is "createAttachment(CreateAttachmentParamsBean createAttachmentParamsBean)". So how can I implement a CreateAttachmentParamsBean? Can anyone help me?
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam and Tommy,
Please could you share the complete code ? I tried use the code above , but it not worked.
Thanks in Advance
Best Regards
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam; I want to simple attach file to the issue without copying but when i attach the file using bellow code it will delete that file from directory. so for the next issue it give FileNotFoundException.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
File file = new File("C:\\Documents and Settings\\eQuest\\Desktop\\Geometric\\test.txt"); ChangeItemBean changeItemBean = attachmentManager.createAttachment(file, file.getName(), "text/plain", user, issue, new HashMap(), time);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried saving the attachments into a temporaryAttachmentMonitor but it's not working because I can't cast an attachment to a temporaryattachment:
AttachmentManager attachManager = ComponentManager.getInstance().getAttachmentManager();
List<Attachment> myAttachments = attachManager.getAttachments(issue);
TemporaryAttachmentsMonitor myTempAttachments =
new TemporaryAttachmentsMonitor();
for (Attachment attachment : myAttachments)
{
myTempAttachments.add( attachment);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know I can use AttachmentManager.getAttachments(Issue) to get all the attachments available on a particular issue, but how do I transfer these attachments onto another issue?
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.