Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

To pass arraybuffer to html web ressource

Posted on by 1,145

Hello Everybody,

First of all I am working on CRM Online 8.2

I'm trying to download a file, using this code:

     var blob = new Blob([file],
{
type: type
});
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
if (filename)
{
var a = document.createElement("a");
if (typeof a.download === 'undefined')
{
window.location = downloadUrl;
}
else
{
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
}


Assuming that "document.createElement" is not supported, I found another solution, that is using an Html page that holds the download.

The probleme is that I dont know how to pass blob to the html,  I tried:

var customParameters = encodeURIComponent("first="+blob+");

Xrm.Utility.openWebResource('Shared/Download',customParameters,300,300);

Unfortunatly does'nt work.

Have you any idea?

Thank you

Regards,

Saad

*This post is locked for comments

  • saadzag Profile Picture
    saadzag 1,145 on at
    RE: Download file from HTML page

    Hello,

    The content of files, is in arraybuffer. And I cannot pass arraybuffer using query string.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Download file from HTML page

    You can try the following (though this is browser based):

    if (binaryPDFContent != null && navigator.msSaveBlob)

       navigator.msSaveBlob(new Blob([binaryPDFContent], { type: mimetype }), "MyDoc.docx");

    else

    {

      var blob = new Blob([binaryPDFContent], { type: mimetype });

      var downloadUrl = URL.createObjectURL(blob);

      var a = document.createElement("a");

      document.body.appendChild(a);

      a.style = "display: none";

      a.href = downloadUrl;

      a.download = "MyDoc.docx";

      a.click();

      URL.revokeObjectURL(downloadUrl);

    }

    The else portion, you already had, but try using navigator.msSaveBlob

    Hope this helps.

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Download file from HTML page

    Hi  ,

    I am not sure about that as this is also not a good idea to pass file content using query string with limited size. As an alternate if you get the file content in your onload of web resource and then append file content using  document.createElement , may be this is one approach you can do.

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

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans