Files
artcraft/app/pages/PageEnigma/comps/GenerateModals/utils/downloadFile.ts
T
wilandwil 7fb2375acc Problem: Download Link is a Blob (#349)
- fixed by giving a proper filename.
- not fixed: filename exists, but is untitled, need to wait for backend
update to get a proper title

Co-authored-by: wil <wil@storyteller.ai>
2024-05-08 16:17:14 -04:00

30 lines
657 B
TypeScript

import { AddToast, ToastTypes } from "~/contexts/ToasterContext";
export const downloadFile = ({
url,
addToast,
title,
}:{
url: string,
addToast: AddToast,
title: string
}) => {
console.log(url);
fetch(url)
.then((resp) => resp.blob())
.then((blob) => {
const blobUrl = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = blobUrl;
a.download = `${title}.mp4`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(() => addToast(ToastTypes.ERROR, "Could not download file."));
};
//check