1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import axios from 'axios';
axios({ url: 'https://test.com/xxxx.pdf', method: 'get', responseType: 'blob', onDownloadProgress: (evt) => { const progress = Number(((evt.loaded / Number(evt.total)) * 100).toFixed()); }, }).then(res => { const contentDisposition = res.headers['content-disposition']; let fileName = contentDisposition?.split(/filename=/)[1];
const a = document.createElement('a'); const URL = window.URL || window.webkitURL; const herf = URL.createObjectURL(res.data); a.href = herf; a.download = fileName; document.body.appendChild(a); a.click(); document.body.removeChild(a); window.URL.revokeObjectURL(herf); })
|