-
-
Save suissa/e54642f839fcfd4295888158f2312ded to your computer and use it in GitHub Desktop.
downloads using fetch
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
export const download = async (params = {}) => { | |
const caching = await fetch(params.url, params) | |
const fileName = caching.headers.get('Content-Disposition') | |
const ext = fileName.split('.')[fileName.split('.').length - 1].replace('"', '') | |
const blob = await caching.blob() | |
const url = await URL.createObjectURL(blob) | |
const a = document.createElement("a"); | |
a.href = url | |
a.download = `Reports.${ext}` | |
a.click() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment