Last active
May 2, 2019 11:09
-
-
Save bitsprint/72f5cf7382764ba28c12843e2b9e0cf2 to your computer and use it in GitHub Desktop.
Automatically initiate a file download in the user's browser
This file contains hidden or 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 generateDownload = report => { | |
var downloadLink = document.createElement('a'); | |
downloadLink.style = 'display: none'; | |
document.body.appendChild(downloadLink); | |
var blob = new Blob([report.data], { | |
type: 'application/octet-stream', | |
}); | |
var url = window.URL.createObjectURL(blob); | |
downloadLink.href = url; | |
downloadLink.download = report.filename; | |
downloadLink.click(); | |
window.URL.revokeObjectURL(url); | |
document.body.removeChild(downloadLink); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was used to allow user to select rows in a grid and generate an Excel report from them in the browser.