push rasad front on new repo
This commit is contained in:
26
src/data/download-file.js
Normal file
26
src/data/download-file.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user