Utilities
Download trigger

Download Trigger

Trigger file downloads programmatically.

Motivation

The DownloadTrigger component provides a convenient way to programmatically trigger file downloads in web applications. It handles the complexities of downloading files, whether they are URLs, Blobs, or other data types.

Examples

Basic

Pass the data you want to download to the data prop, and specify the fileName and mimeType of the file.

Example not found

Download SVG

Here's an example of how to download an SVG file.

Example not found

Promise

You can also trigger downloads from a promise that returns a Blob, File, or string.

Example not found

API Reference

DownloadTrigger

PropDefaultType
data
DownloadableData | (() => MaybePromise<DownloadableData>)

The data to download

fileName
string

The name of the file to download

mimeType
FileMimeType

The MIME type of the data to download

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.