How to get confluence page attachments as BLOB

Hi all,

I am running into an issue of getting downloading attachments that were attached to the confluence page. I need to download as a BLOB but using AP.request is making it difficult in doing so. We are making a call to download/attachments/{id}/{filename}. We get a response with xhr and png binary data in the body.

I’m sure others are having issues with downloading files while using the AP.request so I’m wondering how should I proceed? We also tried passing the png binary data into new Blob with the type 'application/octet-stream" to no avail.

Thanks for any help!

1 Like

i have a such issue, but for now i can download files with a get request such this

Response.ResponseBuilder response = Response.ok(file);
        response.header("Content-Disposition", "attachment;filename=filename.log");


You are not blocked trying to get images from Atlassian?

We are forced to make the request through AP because if we make our own, we will get blocked by CORS. Since we are going from the iframe on our site to the cloud site, we get blocked unless using AP.request

After investigating and trying around for quite a while I have come to the conclusion that this is not possible. Confluence uses XMLHttpRequest to make the requests and returns its responseText. As documented in a really old blog post, XMLHttpRequest.responseText has all bytes above 0x7f translated to 0xfd, so the data is corrupt and there is no way to convert it back to a proper binary buffer.

Confluence is very restrictive regarding what options can be passed on to XMLHttpRequest, so I don’t think there is any way to make this work.

We can access image attachments by including them in a simple img tag, but this does not work in browsers where third-party cookies are disabled, because the attachment page redirects to the login page in that case. This means that we have no reliable way to display attached images to the user in our app.

There is ACJIRA-2379 for the same problem in Jira.


This issue was being tracked as CONFCLOUD-72542 and is now resolved.

Passing the new parameter binaryAttachment: true to AP.request() will cause the response to have a response ArrayBuffer rather than a responseText string.