Here is the thing,
I have a WebResource connected to a Ribbon Button that calls a flow.
The Flow gets a Word Template from my OneDrive, converts it to PDF(Preview) and sends it back to the Javascript Web Resource using HTTP Response.
The document is then downloaded, but when I open it, it says "We can't open this file".
Here is the Flow Response:
And here is the code that is used to fetch the response and download it:
function downloadFile(blob, fileName) {
debugger;
if (navigator.msSaveBlob) { // IE 10
navigator.msSaveBlob(blob, fileName);
} else {
var link = document.createElement("a");
if (link.download !== undefined) {
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", fileName);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
}
The entire code is pretty much a copy paste of this with a few changes:
https://www.itaintboring.com/powerapps/how-to-add-a-ribbon-button-that-calls-a-power-automate-flow/
I suspect it is something to do with the Content-Type, or the fact that the file is Converted(Preview) and not Saved to OneDrive.