Skip to content

Instantly share code, notes, and snippets.

@angelikatyborska
Created October 23, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelikatyborska/86ae44dbaa0094dbbe1f08fd04a44816 to your computer and use it in GitHub Desktop.
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)
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