refactor downloading file

This commit is contained in:
liamcottle 2025-01-01 20:55:56 +13:00
parent 372e61ed7c
commit 82c67bb71c
2 changed files with 36 additions and 8 deletions

View file

@ -0,0 +1,28 @@
class DownloadUtils {
static downloadFile(filename, blob) {
// create object url for blob
const objectUrl = URL.createObjectURL(blob);
// create hidden link element to download blob
const link = document.createElement('a');
link.href = objectUrl;
link.download = filename;
link.style.display = "none";
document.body.append(link);
// click link to download file in browser
link.click();
// link element is no longer needed
link.remove();
// revoke object url to clear memory
setTimeout(() => URL.revokeObjectURL(objectUrl), 10000);
}
}
export default DownloadUtils;