initial
This commit is contained in:
26
layers/shared/utils/download-file.ts
Normal file
26
layers/shared/utils/download-file.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export default (filename: string, content: string | File | Blob) => {
|
||||
let blob: File | Blob
|
||||
|
||||
if (typeof content === 'string') {
|
||||
blob = new File([content], filename, {
|
||||
type: 'text/plain',
|
||||
})
|
||||
}
|
||||
else {
|
||||
blob = content
|
||||
}
|
||||
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.setAttribute(
|
||||
'download',
|
||||
filename,
|
||||
)
|
||||
document.body.appendChild(link)
|
||||
|
||||
link.click()
|
||||
|
||||
window.URL.revokeObjectURL(url)
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
Reference in New Issue
Block a user