0

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.

1 Answer 1

2

As far as I know there is no simple updateAttachment since the file storage follows a version-based approach. Every upload of the same file (by its filename) will be a newer version of the already present file without removing the older one.

To implement your update functionality it might be necessary to do multiple steps:

  1. Check if the file to be uploaded already exists (=update)
  2. Remove a given version or all previous versions using the AttachmentManager
  3. Upload the file

Maybe the CLI implementation gives some more details how they made it because here you can run an update command.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll check out the link you provided ... thank you. I'm also concerned about keeping the versioning history that Confluence offers. If I were to go in through the GUI and upload the file manually, all previous versions will be shown. I need to keep that functionality as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.