如何使用Java API在Atlassian Confluence中更新(不添加额外的)附件?

问题描述 投票:0回答:1

我们有一个自定义插件,允许人们通过GUI上传文档,并在插件中添加有关这些文档的元数据。另外,插件的另一个功能是,我们有一个XML文件通过Confluence SOAP服务推送给我们。此XML文件每天一次由SOAP服务附加到插件空间中的特定文件。

我们现在负责改变这个过程。我们现在将进行自己的SOAP调用以获取相同的XML文件并将其附加到同一页面。

我可以成功地将新文件附加到页面,但是当我尝试使用更新版本更新(替换)该XML文件时,我最终上传了另一个文件,因此我留下了具有相同名称的文件的多个副本,这不是我们想要的。

以下是我添加新附件的内容,但不更新(替换)附件:

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);

同样,我想要的是用更新的filename.xml替换filename.xml,但我得到的是filename.xml,filename.xml,filename.xml等。

java confluence
1个回答
2
投票

据我所知,没有简单的updateAttachment,因为文件存储遵循基于版本的方法。每次上传相同文件(通过其文件名)将是已存在文件的较新版本,而不删除旧版本。

要实现更新功能,可能需要执行多个步骤:

  1. 检查要上传的文件是否已存在(=更新)
  2. Remove a given versionall previous versions使用AttachmentManager
  3. 上传文件

也许CLI implementation提供了一些更详细的信息,因为在这里你可以运行更新命令。

© www.soinside.com 2019 - 2024. All rights reserved.