I have a problem when I tried to download a blob as a file in Chrome.
the code goes like this
const link = document.createElement('a');
const href= window.URL.createObjectURL(blobData)
link.href = href;
link.download = `${fileName}.${fileExtension}`;
link.onclick = () => {
window.URL.revokeObjectURL(href);
};
link.click();
The problem is Chrome will pop up a save as
window, and by the time user confirm the download path the revokeObjectURL
already called which caused the download failed.
I know setTimeout
might solve the problem, but it is confusing. I wonder if there is a solid solution to know when to call revokeObjectURL
.