I create an Iframe on the fly and set as the url a page that downloads a binary file (xls, doc...). While files are downloading I show an animation. When do
Sarkiroka's solution worked for me. I have added an instance id to the cookie name to provide a thread safe solution:
const instanceId = "some uuid retrieved from client";
response.cookie(`fileDownloaded-${instanceId}`,'true', { path: '/', secure: true, maxAge: 90000});
response.header('attachment','your-file-name.any');
//...write bytes to response...
client
var checker = setInterval(()=>{
if(document.cookie.indexOf(`fileDownloaded-${instanceId}`)>-1){
alert('done');
clearInterval(checker);
}
},100);