Created
October 23, 2017 13:54
-
-
Save angelikatyborska/86ae44dbaa0094dbbe1f08fd04a44816 to your computer and use it in GitHub Desktop.
Download a CSV file gotten using fetch (necessary when headers needed, eg. with token authorization)
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
fetch(request).then( | |
response => { | |
if (response.status >= 200 && response.status < 300) { | |
if (response.headers.get('Content-Type') === 'text/csv') { | |
response.text().then( | |
text => { | |
const windowUrl = window.URL || window.webkitURL; | |
const blob = new Blob([text], {type: 'text/csv'}); | |
const url = windowUrl.createObjectURL(blob); | |
window.location = url; | |
} | |
); | |
} | |
} | |
}, | |
response => {} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment