18 lines
451 B
TypeScript
18 lines
451 B
TypeScript
export class FileSaver {
|
|
static saveFile(file: File) {
|
|
const a = document.createElement('a')
|
|
document.body.appendChild(a)
|
|
a.style.display = 'none'
|
|
const url = window.URL.createObjectURL(file)
|
|
a.href = url
|
|
a.download = file.name
|
|
a.click()
|
|
window.URL.revokeObjectURL(url)
|
|
document.body.removeChild(a)
|
|
}
|
|
|
|
static saveBlob(blob: Blob, filename: string) {
|
|
return this.saveFile(new File([blob], filename))
|
|
}
|
|
}
|