mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-12-04 05:40:02 -05:00
refactor downloading file
This commit is contained in:
parent
372e61ed7c
commit
82c67bb71c
2 changed files with 36 additions and 8 deletions
28
src/frontend/js/DownloadUtils.js
Normal file
28
src/frontend/js/DownloadUtils.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue