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.
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.
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.
Here is what I have that adds a new attachment, but does not update (replace) the attachment:
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);
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.