Created
July 16, 2023 03:14
-
-
Save febriliankr/598010ea9fb8b887f0e70873689dcd5e to your computer and use it in GitHub Desktop.
Downloading Blob File in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { data } = await api.get( | |
`/excel`, | |
{ | |
responseType: "blob", | |
} | |
); | |
const url = URL.createObjectURL(data); | |
const link = document.createElement("a"); | |
link.style.display = "none"; | |
link.href = url; | |
const currentDate = new Date().toLocaleDateString("id-ID", { | |
day: "numeric", | |
month: "long", | |
year: "numeric", | |
hour: "numeric", | |
minute: "numeric", | |
second: "numeric", | |
}); | |
link.download = `excel.xlsx`; | |
document.body.appendChild(link); | |
link.click(); | |
window.URL.revokeObjectURL(url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment