download-url.ts
1 /** 2 * Download the file specfied by the given url. 3 * 4 * @param {String} url A url pointing to the file to download. 5 * @param {String} fileName The name that the file should have. 6 */ 7 const downloadUrl = (url: string, fileName: string = 'file') => { 8 const a = document.createElement('a'); 9 document.body.appendChild(a); 10 a.style.display = 'none'; 11 a.href = url; 12 a.download = fileName; 13 a.click(); 14 a.remove(); 15 }; 16 17 export default downloadUrl;