I want to show some kind of notification based on my file download status like it's failed or success. what's the actual problem here it is when I'm clicking download button it's opening default OS popup window like where to save the downloaded file and I'm triggering below method's code on the click of download button and it's showing notification of success before downloading a file. I could not able to do find any resource that can me help out to find the status of downloading of a file
Below is the code of downloading a file
const type = 'text/json';
const fileName = `${programName}.json`;
const data = JSON.stringify(json);
const blob = new Blob([data], { type });
// Create an anchor element and dispatch a click event on it
// to trigger a download
const a = document.createElement('a');
a.download = fileName;
a.href = URL.createObjectURL(blob);
const clickEvt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
a.dispatchEvent(clickEvt);
a.remove();
setOpen(true); // here I'm showing notification
I've tried to show the notification once the file is downloaded I want to show the notification only after the file is either download is success or failure or else if I can listen the save or cancel button event of os window file saver in my code that would also work. It's actually showing the notification before downloading the file because of OS window popup where to save the file