Accessing page attachments from the client side of a macro

Hi,

I’m writing a macro plugin that wants to work with page attachments on the client side. I’ve already set up an atlas-connect environment, but I stuck with this problem.

What I’ve done so far:

  • Using an attachment parameter I get the name of an attachment.
  • Using the /rest/api/content/<pageId>/child/attachment call I get the download url for the attachment. These are looking someting like this: /download/attachments/12345/filename.png?....
  • I can download attachment on the server side by sending a requests with the url above.

The problem is that it doesn’t work on the client side (the view for the macro). If I try to download attachment with full url (like https://username.atlassian.net/wiki/download/attachments/12345/filename.png) I get a CORS error that doesn’t allow me to download the file.

I can workaround it by downloading the file on the server side, and then serving the downloaded content to the client side, but in this case I have to download everything twice.

Do you have any idea how to solve this?

1 Like

Dear @kovacsv ,

downloading text based files via AP.request shouldn’t be a problem. From earlier experiences I know that downloading binary files however was tricky or impossible. I think this Jira ticket might apply for Confluence as well.

In one of our apps we download binary files going through the server as you indicated.

I hope that helps

Andreas

Thanks a lot, @andreas1, I’ll take a look. Unfortunately I have to deal with binary files, too. :frowning:

Hi @kovacsv,
Such endpoint will be provided as part of the Atlassian Developer Status - Attachments download using OAuth in Confluence.

It should be available soon and an announcement will be posted on the community once it is available.

Thanks,
Caterina

Great news, thanks @ccurti!

Dear @ccurti,

I’ve seen the post about the new API endpoint (New Download attachment REST API endpoint), but I don’t think it will solve the problem, because it still won’t work for binary files accessing through AP.request.

Do you think this issue will be solved? Now it prevents me from releasing my app.

Hi @kovacsv, unfortunately you are right: AP.request is currently unable to properly get binary files via this endpoint. I’ve made a ticket to track this: [CONFCLOUD-72542] AP.request unable to get correct binary data through Get URI for download attachment API - Create and track feature requests for Atlassian products..

In the meantime you can try the workaround in the ticket or continue serving the file from the app server-side.

Hi @LucasPan, unfortunately the proposed workaround doesn’t work, because the requests will be blocked by CORS policy. Also, serving everything through the app server is not an option, because it would cause unnecessary server traffic, and unnecessary extra waiting time for users.

Hi @kovacsv - did you end up resolving this issue? We are encountering exactly the same problem with a Spring Boot Atlassian Connect App. The app needs to load a ZIP file attached to a page, uncompress the contents and render. Whilst this all works fine on the server side, ideally it would be performed client side when the dynamic macro renders,

Thanks
Andrew

The issue mentioned by @LucasPan ([CONFCLOUD-72542] AP.request unable to get correct binary data through Get URI for download attachment API - Create and track feature requests for Atlassian products.) is closed now, but I didn’t have time to check it out. But based on the issue, it should work now.