When the button is clicked, I need to display the status "Download in progress" and hide the button. After the download is complete, the button should reappear. The time taken to download the file depends on the number of records the user wants to download. I should not use cookies to notify the client's browser when the download is complete due to platform restrictions. Is there any way to notify the browser that the file download is completed?
Hey Srikanth,
You are asking a very difficult question as you can't really access the browser information like that.
A possible workaround is using a cookie, but unfortunately that's a no go for you....
What's left is storing the entire blob in memory.Basically, when the user clicks a button, you run a bit of javascript which downloads the file (using fetch()) after it's finished you notify the user by making changes to the DOM or an alert or something.
Example:
async function downloadFile(url) { var response = await fetch(url); var blob = await response.blob();
return blob;}.....downloadFile('https://site.com/myfile.exe').then(blob => { // trigger a message here that the file is finished downloading, or whatever you want to do // with the code below you can directly download the file to the users device var url = window.URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = 'myfile.exe'; document.body.appendChild(a); // fix for firefox a.click(); a.remove();});.....
then() triggers after an async function has completed.The big problem with this solution, is that if you download a file of several GB's, it will be put into the users memory. So for very big files this won't work.