fix: simplify download api

This commit is contained in:
Lucas Smith
2024-02-21 02:19:35 +00:00
parent 39c6cbf66a
commit aba6b58c14
3 changed files with 46 additions and 32 deletions

View File

@ -0,0 +1,19 @@
export type DownloadFileOptions = {
filename: string;
data: Blob;
};
export const downloadFile = ({ filename, data }: DownloadFileOptions) => {
if (typeof window === 'undefined') {
throw new Error('downloadFile can only be called in browser environments');
}
const link = window.document.createElement('a');
link.href = window.URL.createObjectURL(data);
link.download = filename;
link.click();
window.URL.revokeObjectURL(link.href);
};