First of all I am working on CRM Online 8.2
I'm trying to download a file via button, using this code: first:
xhr.onload = function (e) {
var arraybuffer = xhr.response;
var fileArray = new Uint8Array(arraybuffer);
var file = fileArray.buffer.slice(fileStart, lastBoundary);
Then:
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, filename);
}
else {
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 by Microsoft, I found another solution, that is using an Html page that holds the download.
the file is an arraybuffer, so I cannot pass it to the function :
Xrm.Utility.openWebResource('Shared/Download',customParameters,300,300);
Because customParameters cannot only stock strings.
Have you any idea to accomplish that?
At your disposal
Saad
Ok here is the solution, I found that we can convert arraybuffer to string and vice versa.
/**
* Convert an Uint8Array into a string.
*
* @returns {String}
*/
function Decodeuint8arr(uint8array){
return new TextDecoder("utf-8").decode(uint8array);
}
/**
* Convert a string into a Uint8Array.
*
* @returns {Uint8Array}
*/
function Encodeuint8arr(myString){
return new TextEncoder("utf-8").encode(myString);
}
For information, if the arraybuffer is too long, it wouldn't work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.