Base64转文件下载 #135
Anuluca Date : 2021-07-13 Tags : 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| async download()}{ await downloadFile().then(res => { let bstr = atob(res) let n = bstr.length let u8arr = new Unit8Array(n) while(n--){ u8arr[n] = bstr.charCodeAt(n) } if(window.navigator && window.navigator.msSaveOrOpenBlob){ window.navigator.msSaveOrOpenBlob(new Blob([u8arr]),'我是文件名') }else{ const link = document.createElement('a') link.href = URL.createObjectURL(new Blob([u8arr])) link.download = '我是文件名' link.click() URL.revokeObjectURL(link.href) } }) }
|