Hello, in my web application (developed in java) I want to display data from a confluence system (running on different server, in other domain).
To obtain the data, I use the REST API. This works fine for textual data from confluence pages. I wonder how can I get the attached files in binary form.
There is no REST API for this. Has anyone a suggestion, how I can achieve this.
This question is related to https://answers.atlassian.com/questions/22650542.
Thanks, Kai
Community moderators have prevented the ability to post new answers.
Hello Kai,
you can use the REST Endpoint CONFLUENCE_BASE/rest/api/content/{id}/child/attachment to get information about the attachment for a content with a given id. The Information contains the URI to access or download the files.
For a page with the attachments my_attachment.pdf and img_welcome.png, the response will look like:
{ "results": [ { "id": "att884780", "type": "attachment", "status": "current", "title": "my_attachment.pdf", "metadata": { "mediaType": "application/pdf", "comment": "" }, "extensions": { "mediaType": "application/pdf", "comment": "" }, "_links": { "webui": "/display/ds/Neue+Space+Homepage?preview=%2F98334%2F884780%2Fmy_attachment.pdf", "download": "/download/attachments/98334/my_attachment.pdf?version=1&modificationDate=1451988725383&api=v2", "self": "http://CONFLUENCE_BASE/rest/api/content/att884780" }, "_expandable": { "container": "", "children": "/rest/api/content/att884780/child", "history": "/rest/api/content/att884780/history", "ancestors": "", "body": "", "version": "", "descendants": "/rest/api/content/att884780/descendant", "space": "/rest/api/space/ds" } }, { "id": "att131105", "type": "attachment", "status": "current", "title": "img_welcome.png", "metadata": { "mediaType": "image/png" }, "extensions": { "mediaType": "image/png" }, "_links": { "webui": "/display/ds/Neue+Space+Homepage?preview=%2F98334%2F131105%2Fimg_welcome.png", "download": "/download/attachments/98334/img_welcome.png?version=1&modificationDate=1325853137007&api=v2", "self": "http://CONFLUENCE_BASE/rest/api/content/att131105" }, "_expandable": { "container": "", "children": "/rest/api/content/att131105/child", "history": "/rest/api/content/att131105/history", "ancestors": "", "body": "", "version": "", "descendants": "/rest/api/content/att131105/descendant", "space": "/rest/api/space/ds" } } ], "start": 0, "limit": 50, "size": 2, "_links": { "self": "http://CONFLUENCE_BASE/rest/api/content/98334/child/attachment", "base": "http://CONFLUENCE_BASE", "context": "/" } }
Best Regards,
Robert
I did the same to get information of all attachments of a page but unfortunately I got 404.
https://<company-domain>/rest/api/content/<page-id>/child/attachment
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You use the Confluence's REST resource GET /rest/api/content/{id}/child/attachment to get a list of attachments. Each entry in the results
array represents one attachment. To get to its data, you access the URL under: _links.download
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andreas,
What do you mean by "access the URL under _links.download"?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the JSON response under "_link" -> "download" there is a URL. Do a GET request on that URL to download the attachment data.
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.
Hi Robert, Hi Andreas, thanks for your answers. The link or download path I had already been determined. I forgot until now, however, to put in URLConnection object the "Authorization" header. Now I have access to the data via URLConnection.getInputStream().
Thanks
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.