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);
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");
}