utils/download: take a string instead of AxiosResponse

This commit is contained in:
Alex Gleason
2022-12-17 20:15:03 -06:00
parent 69a9748b3d
commit b15871aaa8
3 changed files with 10 additions and 12 deletions

View File

@@ -1,9 +1,7 @@
import type { AxiosResponse } from 'axios';
/** Download the file from the response instead of opening it in a tab. */
// https://stackoverflow.com/a/53230807
export const download = (response: AxiosResponse, filename: string) => {
const url = URL.createObjectURL(new Blob([response.data]));
export 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);