copy attachment from other document on fly

核能气质少年 提交于 2020-01-06 01:24:26

问题


After I save my current XPages, in the event postNewDocument of datasources..I would to copy on the fly in the backend Domino Document without saving of disk the attachment from another document andI have found this solution:

  var attachments:java.util.Vector = session.evaluate("@AttachmentNames", docReply);
  for (var i = 0; i < attachments.size(); i++) {
     embeddedObj = docReply.getAttachment(attachments.get(i).toString());
     if (embeddedObj != null) {
       bufferInStream = new java.io.BufferedInputStream(embeddedObj.getInputStream());
     }
  }

How how can I add every attachment stream into a RichTextItem of my current Domino Document?

Tnx

update 29 january 14: Tnx to @Sven I have insert this code into my PostSavedocument event.. But now I have another problem...seem that damage the MIME my "Body" that is the rt mime.

If I open with my Notes Client the document with this RT mime I see only the new attachments and not the original HTML content of CKEDITOR (If I comment the follow code...work correct)....Now I have the problem to re-edit exist MIME filed

 session.setConvertMime(false);
var doc:NotesDocument=document1.getDocument(true);
var mimeRoot:NotesMIMEEntity=doc.getMIMEEntity("Body");
var docAttach:NotesDocument=database.getDocumentByUNID('XXXXXXXUNID'); //doc where are the attachmetns files MIME or RICHTEXT


var XSPReply=wrapDocument(docAttach);  //function in Xsnippets from Opentntf.org
var listattachs=XSPReply.getAttachmentList("Body");

for (var i=0; i<listattachs.length; i++) {
   var is=null;
   var att = listattachs[i];
   var persistentName = att.getPersistentName()==null?att.getName():att.getPersistentName();
   var cid = att.getCID();
   var eo:NotesEmbeddedObject = docAttach.getAttachment(persistentName);
   if (null != eo) {
      var child:NotesMIMEEntity=mimeRoot.createChildEntity(); //create child of original mail
      var emailHeader:NotesMIMEHeader = child.createHeader("Content-Disposition");
      emailHeader.setHeaderVal("attachment; filename=\"" + persistentName+ "\"");
      emailHeader = child.createHeader("Content-ID");
      emailHeader.setHeaderVal("<" + cid + ">");
      var is = new java.io.BufferedInputStream(eo.getInputStream());
      var stream:NotesStream = session.createStream();
      stream.setContents(is);
      child.setContentFromBytes(stream, att.getType(),NotesMIMEEntity.ENC_IDENTITY_BINARY);
    }
}

doc.closeMIMEEntities(true,"Body")
doc.save()
session.setConvertMime(true);

回答1:


You can try to add the attachments as MIME Entities. Have a look here for an example: Link



来源:https://stackoverflow.com/questions/21386897/copy-attachment-from-other-document-on-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!