Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

Send body from OneDrive PDF file to JavaScript Resource and then download it

(0) ShareShare
ReportReport
Posted on by 15

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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans