2022-09-08 14:25:02 -07:00
|
|
|
/** Download the file from the response instead of opening it in a tab. */
|
|
|
|
// https://stackoverflow.com/a/53230807
|
2022-12-17 18:15:03 -08:00
|
|
|
export const download = (data: string, filename: string): void => {
|
|
|
|
const url = URL.createObjectURL(new Blob([data]));
|
2022-09-08 14:25:02 -07:00
|
|
|
const link = document.createElement('a');
|
|
|
|
link.href = url;
|
|
|
|
link.setAttribute('download', filename);
|
|
|
|
document.body.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
link.remove();
|
|
|
|
};
|