---
title: "triggerDownload"
description: "Trigger a browser file download from a Blob or URL with a chosen filename, wiring up the temporary anchor and object URL for you."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/file/trigger-download"
---
# triggerDownload

> Trigger a browser file download from a Blob or URL with a chosen filename, wiring up the temporary anchor and object URL for you.

## Usage

`triggerDownload` triggers a browser file download.

> [!WARNING]
> 
> Note
> 
> - Only available in browser environments
> - Some browsers may block automatic downloads

```ts
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')
  }
})

// Download a URL or dataURL (since v1.5.0)
triggerDownload(canvas.toDataURL('image/png'), 'image.png')
```

## API

### `triggerDownload(source, filename)`

Trigger a browser file download.

### Parameters

**source** (`Blob | string`) *required*: The file data; a string is treated as a directly downloadable URL or dataURL and no object URL is created.

**filename** (`string`) *required*: The filename for the download.

## Changelog

See commit history for [src/helpers/file/triggerDownload.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/helpers/file/triggerDownload.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/helpers/file/triggerDownload.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
