import axios from "axios"; export const downloadFile = (fileUrl) => { axios({ url: fileUrl, method: "GET", responseType: "blob", }) .then((response) => { const blob = new Blob([response.data], { type: response.headers["content-type"], }); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "filename.xlsx"; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); }) .catch((error) => { console.error("Error downloading the file:", error); }); };