I have never worked with Confluence until this new project I found myself on. We have a custom plugin that allows people to upload documents through the GUI, and add metadata about those documents within our plugin. Also, another function is we have an XML file being pushed to us through the Confluence SOAP service. This file is attached to a specific page within our plugin space, once a day.
We have now been charged with turning the process around. We will now make a SOAP call to get the same XML file and attach it to the same page. Is there a way, within Confluence, to attach this XML document to the page without having to go through our own SOAP service?
I figured if I got the Page object, I could use the addAttachment() method to do this. However, as I said, I have no Confluence experience. I tried to create a quick test class to get the Page object, but I have no idea how to get the page ID or where I get the PageManager from. Whenever I try to google "attach document to confluence page", it seems like all of the articles have to do with going through the GUI, and I need to do this from the back end, through Java.
Any assistance would be greatly appreciated. Thank you, and have a good day.
Community moderators have prevented the ability to post new answers.
I am using something like...
Attachment attachment = attachmentManager.getAttachment(pageManager.getPage(space.getKey(),"Page title"),"Attachment name"); Attachment previousVersion=null; if(attachment==null) attachment=new Attachment(); else previousVersion=attachment.copy(); attachment.setFilename(...); attachment.setContentType(....); attachment.setFileSize(...); attachment.setContent(PAGE the attachment is attached to!!!!); //thats the trickiest part attachmentManager.saveAttachment(attachment,previousVersion, INPUTSTREAM);
Hope it helps
It's definitely more than I had before ... thank you. What did you mean by "thats the trickiest part"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I mean that by looking the method setContent without consulting then documentation i was expecting some kind of inputstream. It took me a while to realize why i was getting exceptions ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Panos, never mind. I started using the DefaultAttachmentManager. Thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, attachment manager should be injected in the constructor of the class as any xxxManager. Sorry for late reply just saw it :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My apologies for the late reply, but Atlassian has limited me to 3 posts in a 24 hour period, so this has been my first chance to post again. Something weird was happening with my set-up and the AttachmentManager was not getting injected, therefore I thought I needed to use something like the DefaultAttachmentManager instead. After a complete reboot this morning, and nothing else changed, the AttachmentManager started being injected properly. I have no idea why this was happening, but everything appears to be working well now. Thank you so much for your help with this issue. Have a great day. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"I tried to create a quick test class to get the Page object, but I have no idea how to get the page ID or where I get the PageManager from."
You can get the PageManager and any xxxManager by injection:
public class MyClass{ private final PageManager pageManager; public MyClass(PageManager pageManager){ this.pageManager=pageManager; } .... more methods .... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.