Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

To pass arraybuffer to html web ressource

(0) ShareShare
ReportReport
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
    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 - MVP Profile Picture
    30,188 Moderator 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
    50,091 Moderator 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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans