Details
-
Bug
-
Resolution: Done
-
Low
-
None
-
1
-
Minor
-
Description
Issue Summary
Using AP.request to make a call to /wiki/rest/api/content/{id}/child/attachment/{attachmentId}/download, when the attachment is binary data (e.g. an image), results in the response data being incorrect.
This is likely due to the fact that AP.request uses `XMLHttpRequest.responseText`, which overwrites non-ASCII values, thus corrupting any binary attachments.
Note that text attachments work correctly.
Steps to Reproduce
- Add an image attachment on a page
- Call the API to get attachments using any means
GET /rest/api/content/{contentId}/child/attachment
- Note the attachment ID
- Call the download API using AP.request:
GET /rest/api/content/{contentId}/child/attachment/{attachmentId}/download
Expected Results
AP.request should follow the redirect, and the response should be the correct binary data for the image attachment. One should be able to display the image via
<img src='data:image/jpeg;base64,<base64encoded response> />
Actual Results
The binary data response is incorrect.
Workaround
1. If CORS is not in place (e.g. you wish to embed an image within an <img> tag)
Call either of the following APIs with AP.request:
/rest/api/content/{attachmentId}
/rest/api/content/{containerContentId}?expand=children.attachment
and get the _links.download path of the corresponding attachment. Since the call is made in the browser, one can use this value to construct a URL to download the attachment.
For example,
<img src=<baseURL + downloadURL> />
2. If CORS is in place
Make a request to this API from the Connect app server, then serve the result to the client.