triggerDownload
Trigger a browser file download from a Blob with a chosen filename, wiring up the temporary anchor and object URL for you.
Usage
triggerDownload triggers a browser file download.
Note
- Only available in browser environments
- Some browsers may block automatic downloads
import { triggerDownload } from '@movk/core'
// Download a text file
const textBlob = new Blob(['Hello, World!'], { type: 'text/plain' })
triggerDownload(textBlob, 'hello.txt')
// Download JSON data
const data = { name: 'John', age: 30 }
const jsonBlob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
triggerDownload(jsonBlob, 'data.json')
// Download an image
const canvas = document.createElement('canvas')
canvas.toBlob((blob) => {
if (blob) {
triggerDownload(blob, 'image.png')
}
})
API
triggerDownload(blob, filename)
Trigger a browser file download.
Parameters
blob
Blob required
The file data as a Blob.
filename
string required
The filename for the download.
Changelog
No recent changes