title: How do I UPDATE (not add an additional) attachment in Atlassian Confluence with their Java API?
body: <p>We have a custom plug-in that allows people to upload documents through the GUI, and add metadata about those documents within our plug-in. Also, another function of the plug-in, is we have an XML file being pushed to us via the Confluence SOAP service. This XML file is being attached to a specific file within the plug-in space, by the SOAP service, once a day.</p>
  
  <p>We have now been charged with turning the process around. We will now make our own SOAP call to get the same XML file and attach it to the same page.</p>
  
  <p>I can successfully attach a new file to the page, but when I try to update (replace) that XML file with a newer version, I end up uploading another file, so I am left with multiple copies of the file with the same name, which is not what we want.</p>
  
  <p>Here is what I have that adds a new attachment, but does not update (replace) the attachment:</p>
  
  <pre><code>page = pageManager.getPage(spaceKey, pageTitle);
  
  attachment = attachmentManager.getAttachment(page, attachmentFilename);
  Attachment currentAttachment = null;
  
  currentAttachment = (Attachment) attachment.clone();
  
  attachment = new Attachment();
  attachment.setFileName(attachmentFilename);
  attachment.setContent(page);
  
  attachment.setFileSize(fileSize);
  attachment.setContentType(newAttachmentContentType);
  attachment.setCreator(page.getCreator());
  attachment.setCreationDate(date);
  attachment.setComment(attachmentComment);
  
  attachmentManager.saveAttachment(attachment, currentAttachment, dplAsStream);
  </code></pre>
  
  <p>Again, what I want is to replace filename.xml with an updated filename.xml, but what I am getting is filename.xml, filename.xml, filename.xml, etc.</p>