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
Hello,
The content of files, is in arraybuffer. And I cannot pass arraybuffer using query string.
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.
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.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6