PDF Services API - File has been damaged
After copying the code from Postman I can sucessfully gertate (in PHP using cURL) my tokens. I the POLL the returend link in javascript and sucessfully gernerate a respone. Here is part of the Polling code I use in javescript to save the response.
var xhr = new XMLHttpRequest();
xhr.open("GET", '<URL FROM HEADER>', true);
xhr.responseType = "blob";
xhr.setRequestHeader('Authorization', accTok);
xhr.setRequestHeader('x-api-key', '<KEY>');
xhr.onload = function(event) {
if(this.status == 200) {
// Create a new Blob object using the response data of the onload object
var blob = new Blob([this.response], {type: 'application/octetstream'});
//Create a link element, hide it, direct it towards the blob, and then 'click' it programatically
let a = document.createElement("a");
a.style = "display: none";
document.body.appendChild(a);
//Create a DOMString representing the blob and point the link element towards it
let url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'myFile.pdf';
//programatically click the link to trigger the download
a.click();
window.URL.revokeObjectURL(url);
clearInterval(pollInterval);
}else{
//deal with your error state here
}
};
xhr.send();
This generates and saves the PDF File, however this file can oly be opend in a browser. If it try loading it in Adobe Embed PDF Api, it shows up as damaged. When I try to upload myfile.pdf to this forum I get this:
Correct the highlighted errors and try again.
- The attachment's myfile.pdf content type (application/pdf) does not match its file extension and has been removed.
What am I missing?
