2

I am able to attach a file to RichTextItem of a domino document that I receive as an InputStream. Below is the code snippet:

attachDocument(InputStream is){
    .....
    File attFile = saveInputStr(is);
    Document attdoc = testdb.createDocument();
    attDoc.replaceItemValue("Form", "formAttachment");
    RichTextItem rti = (RichTextItem) attDoc.getFirstItem("attachment");
    rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", attFile .getPath(), attFile .getName());
    .....
}

This works fine. But what if I don't want to write the file to disk, like I save it to a File i.e. attFile in the above snippet. Is there a way that to write the contents of InputStream to a file (may be using some notes document) and attach it with out saving to disk.

Naveen
  • 6,786
  • 10
  • 37
  • 85
ranjan
  • 1,739
  • 5
  • 18
  • 22
  • Where are you getting the `InputStream is`? I mean what is the source of it, another `embeddedObj.getInputStream()` or something else? – Naveen Jul 02 '13 at 14:16
  • sorry for replying late..ya I get the input stream like this.. I got the solution for this. I have answered it below.. – ranjan Jul 07 '13 at 09:52

2 Answers2

3

I actually found solution for my question. Maybe it will be helpful for someone

attachDocument(InputStream is){
        .....
        //File attFile = saveInputStr(is);
        Document attdoc = testdb.createDocument();
        attDoc.replaceItemValue("Form", "formAttachment");
        //RichTextItem rti = (RichTextItem) attDoc.getFirstItem("attachment");
        //rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", attFile .getPath(), attFile .getName());
        attDoc.getFirstItem("attachment");
        Stream stream = DominoUtils.getCurrentSession().createStream();
        stream.write(IOUtils.toByteArray(is));
        MIMEEntity me = attDoc.createMIMEEntity("attachment"); 
        me.setContentFromBytes(stream, "application/pdf", MIMEEntity.ENC_IDENTITY_8BIT);
        is.close();
        attdoc.save();
        .....
    }
ranjan
  • 1,739
  • 5
  • 18
  • 22
2

Via the JAVA API (or LotusScript, COM) I don't see a way to add an attachment to a rich text item using anything but the embedObject method. And unfortunately the embedObject method only takes a string pointing to the file location to be imported. Without a way to pass in an actual object it seems you are required to have the file on disk and pass the path to that file.

Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63
  • This is correct. Our methodology is generally to create a folder on the file system and clean up and delete it when done. – Aaron Brake Jul 03 '13 at 14:40