@Override public ChangeItemBean createAttachment(File file, String filename, String contentType, ApplicationUser author, Issue issue) throws AttachmentException { validateAttachmentLimitSize(file, filename); final ChangeItemBean changeItemBean = attachmentManager.createAttachment(file, filename, contentType, author, issue); if (changeItemBean != null) { monitor.info("Added attachment to issue '" + issue.getKey() + "'"); } return changeItemBean; }
public ChangeItemBean createAttachment(final MultiPartRequestWrapper requestWrapper, final ApplicationUser remoteUser, final GenericValue issue, final String fileParamName, final Map<String, Object> attachmentProperties) throws AttachmentException { final File file = requestWrapper.getFile(fileParamName); if (file == null) //there's not much we can do here. { log.warn(format("Could not create attachment. No file found in MultiPartRequestWrapper. File param name: %s. Request wrapper file names: %s.", fileParamName, CollectionBuilder.list(requestWrapper.getFileNames()))); return null; } final String filename = requestWrapper.getFilesystemName(fileParamName); final String contentType = requestWrapper.getContentType(fileParamName); return attachmentManager.createAttachment(file, filename, contentType, remoteUser, issue, attachmentProperties, UtilDateTime.nowTimestamp()); }
/** * Attaches files using the method outlined in Fear of attachments at http://www.iseran.com/Steve/papers/fear-of-attachments.pdf * and http://marc.theaimsgroup.com/?l=axis-user&m=109103923030924&w=2 * * @return boolean */ private boolean addAttachmentToIssueFromMimeAttachments(User user, String[] fileNames, Issue issueToAttach) throws RemoteException, RemotePermissionException { String formToken = "issuetoken-" + issueToAttach.getId(); try { File[] files = attachmentHelper.saveFile(fileNames, issueToAttach, formToken); for (int i = 0; i < files.length; i++) { File file = files[i]; attachmentManager.createAttachment(file, fileNames[i], GENERIC_CONTENT_TYPE, user, issueToAttach); } } catch (Exception e) { log.warn("Unable to attach files through the SOAP interface", e); throw new RemoteException("Unable to attach files.", e); } return true; }
private List<ChangeItemBean> convertTemporaryAttachments(final ApplicationUser user, final Issue issue, final List<Long> selectedAttachments, final TemporaryAttachmentsMonitor temporaryAttachmentsMonitor, final String attachScreenshotFileName) throws AttachmentException { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // NOTE: this method has been copied from attachment manager and changed to accept fileName specified in Screenshot Attachment Dialog ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// notNull("issue", issue); notNull("attachScreenshotFileName", attachScreenshotFileName); notNull("selectedAttachments", selectedAttachments); notNull("temporaryAttachmentsMonitor", temporaryAttachmentsMonitor); final List<ChangeItemBean> ret = new ArrayList<ChangeItemBean>(); for (final Long selectedAttachment : selectedAttachments) { final TemporaryAttachment tempAttachment = temporaryAttachmentsMonitor.getById(selectedAttachment); final ChangeItemBean cib = attachmentManager.createAttachment(tempAttachment.getFile(), attachScreenshotFileName, tempAttachment.getContentType(), user, issue, Collections.<String, Object>emptyMap(), UtilDateTime.nowTimestamp()); if (cib != null) { ret.add(cib); } } //finally clear any other remaining temp attachments for give form token temporaryAttachmentsMonitor.clearEntriesForFormToken(formToken); return ret; } }
for (FilePart filePart : fileParts) ChangeItemBean bean = attachmentManager.createAttachment(getFileFromFilePart(filePart), filePart.getName(), filePart.getContentType(), authContext.getUser(), issue, Collections.<String, Object>emptyMap(), nowTimestamp());
changeItemBeans.add(attachmentManager.createAttachment(tempFile, fileName, GENERIC_CONTENT_TYPE, user, issue));