0

What is the best place to put some temporary files that will become attachments later(by means of embedObject)? Are there any temporary folders for xpages that can be obtained and used for this purpose?

Or is there a way to create atachments from stream without use of intermediary files?

W_K
  • 868
  • 4
  • 9
  • 3
    In my opionion the best place is the *Temp* directory on the server. You can use *System.getProperty("java.io.tmpdir")* to get the path. And yes, there are some XPages specific temp folders. What your are trying to do? – Sven Hasselbach Jan 09 '13 at 11:10
  • Nothing special - just add dynamically created pdf to a document without compromising security. Does xpages have access to system temp dir by default or do I have to add some grants ? – W_K Jan 09 '13 at 11:47

1 Answers1

1

You can do something like this with the MIMEEntity. Then you will be able to stream an attachment right into your notesdocument. You will have to get a handle to a notesdocument and an outputstream with the file content. Then you can try to do something like I have done in the code snippet here.

        MIMEEntity m = newDoc.createMIMEEntity( fieldNameForFiles );
        MIMEHeader header = m.createHeader("content-disposition");
        header.setHeaderVal("attachment;filename=\"" + this.getFileName() + "\"");
        Stream oStream = session.createStream();
        InputStream is = new ByteArrayInputStream( ((ByteArrayOutputStream)outStream).toByteArray() );
        oStream.setContents(is);
        m.setContentFromBytes(oStream, "application/pdf", MIMEEntity.ENC_IDENTITY_BINARY); 
        m.decodeContent();
        newDoc.save(true, true);
Ketil
  • 26
  • 1