63 Application app = Application.getApplication();
64 Media[] medias =
event.getMedias();
65 if(medias ==
null || medias.length == 0)
return;
66 for(Media media : medias) {
67 Attachment attachment =
new Attachment();
68 attachment.setModification(
new Date());
69 attachment.setPath(entityPath);
70 attachment.setOwner(app.getConstructor().getUser().getId());
71 attachment.setOnlyOwner(
false);
72 attachment.setComment(
"");
73 attachment.setShowKey(
null);
74 attachment.setPublishable(
true);
75 AttachContent ac =
new AttachContent();
76 if(media.inMemory()) {
77 ac.setFileContent(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
79 byte[] buffer =
new byte[102400];
80 InputStream is = media.isBinary() ? media.getStreamData() :
new ReaderInputStream(media.getReaderData(), Charset.defaultCharset());
81 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
83 while((r = is.read(buffer)) != -1) {
84 baos.write(buffer, 0, r);
87 ac.setFileContent(baos.toByteArray());
89 attachment.setAttachContent(ac);
90 attachment.setFileName(media.getName());
91 attachment.setFileContentType(media.getContentType());
92 attachment.setFileSize(ac.getFileContent().length);
93 attachment.setValidated(app.isInRole(
"attach:self-validate"));
94 attachment =
new AttachPU().saveObject(attachment);
95 SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, attachment,
"uploaded",
null);