getDownload(url, body, params) { | |
this.query(url, body, params, 'GET').then(resp => { | |
resp.blob().then(blob => this.blobDownload(blob, resp)); | |
}); | |
} | |
blobDownload(blob, resp) { | |
const fileName = (resp.headers.get('Content-Disposition') || '').match(/filename="?(.+[^"])"?/)[1]; // matches `filename="a.b"` or `filename=a.b` as 'a.b' | |
if (window.navigator && window.navigator.msSaveOrOpenBlob) { | |
window.navigator.msSaveOrOpenBlob(blob, fileName); | |
} else { | |
const url = window.URL.createObjectURL(blob); | |
const anchor = document.createElement('a'); | |
anchor.download = fileName; | |
anchor.href = url; | |
anchor.style = 'display: none'; | |
document.body.appendChild(anchor); | |
anchor.click(); | |
setTimeout(() => { | |
window.URL.revokeObjectURL(url); | |
anchor.remove(); | |
}, 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment