Skip to content

Instantly share code, notes, and snippets.

@yoandresaav
Created February 4, 2021 23:11
Show Gist options
  • Save yoandresaav/228c274a359f457088ad84fcbe5193f7 to your computer and use it in GitHub Desktop.
Save yoandresaav/228c274a359f457088ad84fcbe5193f7 to your computer and use it in GitHub Desktop.
const downloadCVs = async () => {
const url = window.django.urls.get_documens_cvs_for_have_company_whitout_member;
const response = await axios.get(url, {params: { applicant: applicant.id }, responseType: 'arraybuffer'});
let fileName = response.headers["content-disposition"].split("filename=")[1];
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // IE variant
window.navigator.msSaveOrOpenBlob(new Blob([response.data], {type: 'application/zip'}),
fileName);
} else {
const blob = new Blob([response.data], {type: 'application/zip'});
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', response.headers["content-disposition"].split("filename=")[1]);
document.body.appendChild(link);
link.click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment