Hi.
I know it's not possible to rename JIRA attachments (https://answers.atlassian.com/questions/103334)
I was wondering how to do it using a plugin. I didn't see any functionality for it in AttachmentManager or Attachment classes. Do I have to go directly to database ([JIRA].[dbo].[fileattachment].[FILENAME])? I know that it has to be possible in some way - These guys are doing it.
Community moderators have prevented the ability to post new answers.
My approach would be extracting the file for the attachment. Delete the old attachment, rename the file and create a new attachment for it.
List<Attachment> attachments = attachmentManager.getAttachments(issue); for (Attachment attachment : attachments) { String filePath = PathUtils.joinPaths(attachmentPathManager.getAttachmentPath(), issue.getProjectObject().getKey(), issue.getKey(), attachment.getId().toString()); File atFile = new File(filePath); atFile.rename(....); if (atFile.exists()) { CreateAttachmentParamsBean createAttachmentParamsBean = new CreateAttachmentParamsBean(atFile, attachment.getFilename(), attachment.getMimetype(), attachment.getAuthorObject(), mutableIssueObject, attachment.isZip(), attachment.isThumbnailable(), null, attachment.getCreated(), true); if (atFile.canRead()) { try { attachmentManager.createAttachment(createAttachmentParamsBean); } catch (AttachmentException e1) { e1.printStackTrace(); } } } attachmentManager.deleteAttachment(attachment); }
Issue is the issue you want to change the attachment for. mutableIssueObject is the mutable version of that issue (you might not need a mutable issue here, not sure).
atFile is the file that should be renamed with atFile.rename(). Delete old attachment afterwards.
Hope that helps. If so, please accept my answer.
Thanks for the suggestion. I'm gonna accept this answer since it should probably work. But I don't like the approach of downloading & reuploading - it feels rather messy. My solution (and what I ended up doing) is this: Attachment oAttachment = attachmentManager.getAttachment(icAttachmentId); Issue oIssue = oAttachment.getIssueObject(); if(permissionManager.hasPermission(Permissions.CREATE_ATTACHMENT, oIssue, getLoggedInUser())) { OfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class); for (GenericValue attachment : delegator.findByField("FileAttachment", "id", icAttachmentId)) { attachment.setString("filename", scFileName); attachment.store(); } } It's been working for about 2 weeks without any problems.
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.
Hi, Thanks for the useful code. But I am new to JIRA administration and I need some more help please. My question is: How do I run this code? Should I run it by Script runner post function? and is the code complete or should I include some header statements?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, Andris.
You can try our add-on - Smart Attachments. It allows you to rename attachments, put them into categories, perform bulk operations, load files to categories via drag-n-drop and other features.
If you have any questions about the add-on, feel free to contact me via vrutkevich@stiltsoft.com.
Thanks.
Best Regards,
Vadim Rutkevich
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Heh, in case you didn't notice - I already linked to your plugin as a proof that it's possible to do this. The problem is that paying over 1000$ for ability to rename attachments is ridiculous. But it doesn't matter now. I added the renaming functionality myself. Thanks for replying though. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andris, we can give you a very good discount if you decide to purchase our add-on. Please contact me (vrutkevich@stiltsoft.com) to discuss details if you want. I am sure you will be satified with the discount. Besides renaming, you get other useful features for better performance in JIRA. Thanks. Best Regards, Vadim Rutkevich
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the offer but we are using JIRA 5.1 and your plugin supports 6.0+. So it wouldn't work anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you're on a Mac - I can help you...tested on Jira Server.
You cannot "rename" one already uploaded, but you can name it upon upload from a screenshot.
1. Grab a screenshot
Cmd+Ctrl+Shift+4 (select the part to clip) or
Cmd+Ctrl+Shift+3 (selects entire screen)
2. View Ticket
3. Cmd+V (pastes from clipboard)
4. Name it and select Upload.
see screenshot
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vote for suggestion - Add a REST call for renaming attachments
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.