remove object URL after download
This commit is contained in:
parent
60c218497a
commit
312cfa3069
|
@ -32,16 +32,8 @@ export function downloadAsFile(filename: string, content: string) {
|
||||||
const file = new Blob([content], {
|
const file = new Blob([content], {
|
||||||
type: 'text/plain',
|
type: 'text/plain',
|
||||||
});
|
});
|
||||||
const a = document.createElement('a');
|
const fileURL = URL.createObjectURL(file);
|
||||||
a.href = URL.createObjectURL(file);
|
downloadUsingAnchor(fileURL, filename);
|
||||||
a.download = filename;
|
|
||||||
|
|
||||||
a.style.display = 'none';
|
|
||||||
document.body.appendChild(a);
|
|
||||||
|
|
||||||
a.click();
|
|
||||||
|
|
||||||
a.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadFile(
|
export async function downloadFile(
|
||||||
|
@ -116,10 +108,6 @@ export async function downloadFile(
|
||||||
tempURL = URL.createObjectURL(fileBlob);
|
tempURL = URL.createObjectURL(fileBlob);
|
||||||
downloadUsingAnchor(tempURL, file.metadata.title);
|
downloadUsingAnchor(tempURL, file.metadata.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempURL && URL.revokeObjectURL(tempURL);
|
|
||||||
tempImageURL && URL.revokeObjectURL(tempImageURL);
|
|
||||||
tempVideoURL && URL.revokeObjectURL(tempVideoURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadUsingAnchor(link: string, name: string) {
|
function downloadUsingAnchor(link: string, name: string) {
|
||||||
|
@ -129,6 +117,7 @@ function downloadUsingAnchor(link: string, name: string) {
|
||||||
a.download = name;
|
a.download = name;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
|
URL.revokeObjectURL(link);
|
||||||
a.remove();
|
a.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue