pleroma/packages/pl-fe/src/utils/download.ts
marcin mikołajczak 4d5690d0c1 Switch to workspace
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-08-28 13:01:08 +02:00

13 lines
428 B
TypeScript

/** Download the file from the response instead of opening it in a tab. */
// https://stackoverflow.com/a/53230807
const download = (data: string, filename: string): void => {
const url = URL.createObjectURL(new Blob([data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
link.remove();
};
export { download };