Skip to content

Instantly share code, notes, and snippets.

@febriliankr
Created July 16, 2023 03:14
Show Gist options
  • Save febriliankr/598010ea9fb8b887f0e70873689dcd5e to your computer and use it in GitHub Desktop.
Save febriliankr/598010ea9fb8b887f0e70873689dcd5e to your computer and use it in GitHub Desktop.
Downloading Blob File in React
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