Last active
May 19, 2023 14:37
-
-
Save abzeede/840ae62a3b7db5127d177ad072114265 to your computer and use it in GitHub Desktop.
download pdf file with axios
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 getPdfInvoice = async () => { | |
let csrfToken = document.getElementsByName('csrf-token')[0].content | |
try { | |
const resp = await axios.get('ENDPOINT', { | |
responseType: 'blob', | |
}) | |
// create temp download url | |
const downloadUrl = window.URL.createObjectURL(resp.data) | |
// open pdf file on new tab | |
window.open(downloadUrl, '__blank') | |
// remove temp url | |
window.URL.revokeObjectURL(url) | |
return resp | |
} catch (e) { | |
throw e | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment