Uploaded image for project: 'Confluence Cloud'
  1. Confluence Cloud
  2. CONFCLOUD-72542

AP.request unable to get correct binary data through Get URI for download attachment API

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Low
    • Ecosystem
    • None

    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

      1. Add an image attachment on a page
      2. Call the API to get attachments using any means
        GET /rest/api/content/{contentId}/child/attachment
        
      1. Note the attachment ID
      2. 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.

      Attachments

        Issue Links

          Activity

            People

              111c7764d6a3 Preethi K
              cd055fd0d3e8 Lucas Pan
              Votes:
              6 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: