-1

I want to trigger a file download when the process in complete, (without using Drive service).

I send the encoded data back to client where the client load the encoded data inside an iframe (since the mime is zip it triggers a download).

However, I am unable to get a download of zip when the data is large.

I have tried with

Code.gs

//zipBlob = some zipped binary data
 return {
                    'contents': "data:application/zip;base64, " + Utilities.base64Encode(zipBlob.getAs("application/zip").getBytes())
                };

HTML Sidebar

    if (typeof d === 'object') {
       if (d.contents)
            window.open("aboutblank", "Preview").document.write('<head><style>body{margin:0}</style></head><iframe id="iframe" src="' + d.contents + '" scrolling="auto" frameborder="0px" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe>');
    }
Code Guy
  • 3,059
  • 2
  • 30
  • 74

1 Answers1

0

I found an answer,

 download("export."+d.ext, d.contents)

var download=function(c,b){var a=document.createElement("a"),d=dataURLtoBlob(b);a.setAttribute("href",URL.createObjectURL(d));a.setAttribute("download",c);a.style.display="none";document.body.appendChild(a);a.click();var e;a.addEventListener("click",e=function(){requestAnimationFrame(function(){URL.revokeObjectURL(a.href)});a.removeAttribute("href");a.removeEventListener("click",e)});document.body.removeChild(a)},dataURLtoBlob=function(c){var b=c.split(",");c=b[0].match(/:(.*?);/)[1];if(-1!==b[0].indexOf("base64")){b=
atob(b[1]);for(var a=b.length,d=new Uint8Array(a);a--;)d[a]=b.charCodeAt(a);return new Blob([d],{type:c})}b=decodeURIComponent(b[1]);return new Blob([b],{type:c})};
Code Guy
  • 3,059
  • 2
  • 30
  • 74