问题
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