Exemplo n.º 1
0
 private Attachment prepareAttachment(
     String fileName, String contentType, User user, byte[] contents, String tags) {
   try {
     Attachment a = new Attachment();
     a.setName(fileName);
     a.setMimeType(contentType);
     File root = new File(DEFAULT_UPLOAD_DIRECTORY, user.getLogin());
     root.mkdirs();
     File tmpFile = File.createTempFile("upload_", ".bin", root);
     FileUtils.writeToFile(tmpFile, contents);
     a.setSize((long) contents.length);
     a.setMD5(FileUtils.getMD5(tmpFile));
     a.setFileName(user.getLogin() + "/" + tmpFile.getName());
     return a;
   } catch (Exception ex) {
     return null;
   }
 }