Funções de download
unknown
javascript
a year ago
622 B
7
Indexable
Never
const directDownload = (blob, fileName) => { const ghostLink = document.createElement('a'); document.body.appendChild(ghostLink); ghostLink.style = 'display: none'; const urlFile = window.URL.createObjectURL(blob); ghostLink.href = urlFile; ghostLink.download = fileName; ghostLink.click(); window.URL.revokeObjectURL(urlFile); }; export const downloadFile = (file) => { const xhr = new XMLHttpRequest(); xhr.open('GET', `${file.archiveOceanUrlDescription}`); xhr.responseType = 'blob'; xhr.onload = () => directDownload(xhr.response, file.archiveOriginalName); xhr.send(); };