通过MIME将多个文件附加到Lotus Domino中的文档 [英] Attaching multiple files through MIMEs to a document in Lotus Domino
问题描述
在我们的企业应用程序中,我们需要将文件附加到文档中.我们在字节数组中具有文件名和文件内容.我找到了一种使用MIME将文件附加到文档的解决方案:
In our enterprise application we need to attach files to a document. We have the filename and the content of the file in a byte array. I found a solution to attach a file to a document with MIMEs:
final MIMEEntity body = document.createMIMEEntity(fileName);
final MIMEHeader bodyHeader = body.createHeader("Content-Disposition");
final boolean isHeaderValSet = bodyHeader.setHeaderVal("attachment; filename=\"" + fileName + "\"");
if (!isHeaderValSet) {
throw new ComponentException("Could not set MIME header value.");
}
body.setContentFromBytes(fileContentOutput, mimeType, MIMEEntity.ENC_IDENTITY_BINARY);
final boolean saveSuccessful = document.save();
if (!saveSuccessful) {
throw new Exception("Cannot attach file " + fileName + "to document: " + documentUniversalId);
}
此方法似乎适用于文件,但是当我尝试上传另一个文件时,出现以下异常:
This method seems to work for a file, but when I try to upload another one I get the following exception:
NotesException:项目主体已经存在
NotesException: Item body already exists
当您只有文件名和字节数组中的内容时,是否可以将多个文件附加到文档?
Is there a way to attach multiple files to a document, when you only have the name of the file and the contents in a byte array?
推荐答案
在创建称为"body"的父" MIMEEntity的第一行.然后在一个循环中,为要包括的所有文件创建子MIMEentities:
Keep the first line where you create the "parent" MIMEEntity called body. Then in a loop, create child MIMEentities for all the files you wish to include:
final MIMEEntity child = body.CreateChildEntity;
child.setHeaderVal("attachment; filename=\"" + fileName + "\"");
child.createHeader("Content-Disposition");
child.setContentFromBytes(fileContentOutput, mimeType, MIMEEntity.ENC_IDENTITY_BINARY);
这篇关于通过MIME将多个文件附加到Lotus Domino中的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!