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.