Search code examples
lotus-noteslotus-dominolotus

Extracting attachments from lotus notes api using EmbeddedObject, Creating eo*tm file in system folder


I am trying to extract attachments using EmbeddedObjects, I am able to extract attachments but create em*tm temp files in system temp folder.

 EmbeddedObject embeddedObject=document.getAttachment(attachmentName);
 InputStream inputStream=embeddedObject.getInputStream();
 .....
 ......
 inputStream.close();
 embeddedObject..recycle();
 document..recycle();

After closing input Stream its not deleting temp file form system temp folder. Is it any thing wrong in my code or its setting issue with lotus notes.

Can you please help me in this?

Thanks for the help.


Solution

  • This is a common issue, and it relates to the incorrect closure/recycle of objects (either missing or out of sequence). E0*TM files will be created while the objects are alive and cleaned up when recycled.

    If they are correct then check to see if any Antivirus software running that is blocking deletion.

    The following sample code I used to test this before works, so compare to yours.

      try { 
    
       System.out.println("Start"); 
       String path = "test.txt";    
    
       Session session = getSession();  
       AgentContext agentContext = session.getAgentContext();   
    
       System.out.println("Get DB");    
       Database db = session.getCurrentDatabase();  
    
       System.out.println("View + doc");    
       View vw = db.getView("main");    
       Document doc = vw.getFirstDocument();    
    
       System.out.println("Embedded object");   
       EmbeddedObject att = doc.getAttachment(path);    
       InputStream is = att.getInputStream();   
       ByteArrayOutputStream fos = new ByteArrayOutputStream(); 
    
       byte buffer[] = new byte[(int) att.getFileSize()];   
       int read;    
       do { 
        read = is.read(buffer, 0, buffer.length);   
        if (read > 0) { 
         fos.write(buffer, 0, read);    
        }   
       } while (read > -1); 
    
       fos.close(); 
       is.close();
    
       // recycle the domino variables  
       doc.recycle();   
       vw.recycle();    
       db.recycle();    
       att.recycle();   
    
      } catch (Exception e) {   
       e.printStackTrace(); 
      }