Skip to content

downloadBlob

Downloads a Blob as a file. The helper internally creates an object URL, triggers an anchor click via downloadUrl and revokes the URL afterwards.

Importing

ts
import { downloadBlob } from '@basmilius/utils';

Usage

ts
import { downloadBlob } from '@basmilius/utils';

const blob = new Blob([JSON.stringify({hello: 'world'})], {type: 'application/json'});
downloadBlob(blob, 'hello.json');

Parameters

NameTypeDescription
blobBlobThe binary content to download.
filenamestringThe suggested filename.

Returns

void — the download is triggered synchronously. The browser handles the actual file save dialog.

Type signature

ts
declare function downloadBlob(blob: Blob, filename: string): void;

See also