Issue with data in Jira Cloud Attachment (API returns file of different size)

Hi everyone.
I was working on the ability to download Jira Cloud attachments using JS and, unfortunately, faced issues with the returned data.

Response text contains this:

After I save file on the disc it messages me:
image
image

When I try to get this file using the address line (standard browser downloading) it returns me file with no issues, but here is the difference that I noticed:
image

The difference is about 20Kb. It’s obviously different bunches of data, but unfortunately, I cannot tell why, because I’m using the same endpoint.

I will appreciate any ideas or help.

Details/example:

Using API endpoint: https://myinstance.atlassian.net/secure/attachment/10000/test.docx

function saveFile(blob, filename) {
  if (window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob, filename);
  } else {
    const a = document.createElement('a');
    document.body.appendChild(a);
    const url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = filename;
    a.click();
    setTimeout(() => {
      window.URL.revokeObjectURL(url);
      document.body.removeChild(a);
    }, 0)
  }
}

AP.request({
  url: path,
  success: (responseText) => {
    const blob = new Blob([responseText]);
    saveFile(blob, 'test.docx');
  },
  error: () => {},
});

Hi @piskunovigorm It’s not possible to get binary date with AP.request, see https://ecosystem.atlassian.net/browse/ACJIRA-2379

1 Like

Thank you @marc. But do you know if this is possible some another way? Let’s say httpClient.get() results are pretty close. Does it mean we need to implement our own solution for that?

You need to go through the server, because of security.