protected void commonUploadAttachment() throws IOException { logger.debug("Uploading attachment"); viewAttachmentUrl = null; InputStream attachmentStream = upload.getInputStream(); String attachmentId = RandomUtil.createRandomId(); File dataFile = RandomUtil.getCodeFile( pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId); // copy the data FileOutputStream fileOutputStream = new FileOutputStream(dataFile); IOUtils.copyLarge(attachmentStream, fileOutputStream); if(textConfiguration == null) { textConfiguration = new TextConfiguration(); } Attachment attachment = TextLogic.createAttachment( textConfiguration, attachmentId, upload.getFileName(), upload.getContentType(), upload.getSize()); attachment.setDownloadable(uploadDownloadable); viewAttachmentUrl = generateViewAttachmentUrl(attachmentId); saveConfiguration(textConfiguration); logger.info("Attachment uploaded: " + upload.getFileName() + " (" + attachmentId + ")"); IOUtils.closeQuietly(attachmentStream); IOUtils.closeQuietly(fileOutputStream); upload.delete(); logger.debug("Upload resources cleaned"); }
@Button(list = "manage-attachments", key = "ok", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) public Resolution saveAttachments() { if(downloadable == null) { downloadable = new String[0]; } if(textConfiguration == null) { textConfiguration = new TextConfiguration(); } for(Attachment attachment : textConfiguration.getAttachments()) { boolean contained = ArrayUtils.contains(downloadable, attachment.getId()); attachment.setDownloadable(contained); } saveConfiguration(textConfiguration); return cancel(); }
saveConfiguration(textConfiguration); if (counter == 1) { SessionMessages.addInfoMessage(ElementsThreadLocals.getText("text.attachment.oneDeleted"));