Reputation: 391
I am building a MS Teams app, that should run in a tab. How can I let the user download a file in the app that was generated in the client? In a normal web app running outside Teams I am able to use the saveAs function in https://github.com/eligrey/FileSaver.js, but it doesn't seem to work inside a Teams tab.
I also have tried using the microsoftTeams.openFilePreview(...) function with objectUrl set to a data Url, but it doesn't seem to work either.
Any suggestions?
Upvotes: 0
Views: 1094
Reputation: 391
I couldn't get the solution with iframe to work with a data url, but this solution works:
const link = document.createElement('a');
link.download = filename;
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
where url is a data url (for instance data:application/pdf;base64,JVBERi0xLjMKJbrfrOAKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQ...), and filename is the name of the file to download.
Upvotes: 0
Reputation: 145
Could you please try with below code,
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
ifrm.style.width = "640px";
ifrm.style.height = "480px";
document.body.appendChild(ifrm);
return ifrm;
I have implemented and tested the above code, it is working as expected.
Upvotes: 1