Attaching multiple files through MIMEs to a document in Lotus Domino

倾然丶 夕夏残阳落幕 提交于 2019-12-23 13:06:24

问题


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: 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?


回答1:


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);

CreateChildEntity



来源:https://stackoverflow.com/questions/11294991/attaching-multiple-files-through-mimes-to-a-document-in-lotus-domino

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