-
-
Save mitrofun/758d2d7be0bc1a800891b4f903f18a2a to your computer and use it in GitHub Desktop.
Download a .zip file from a blob URL using Javascript with Fetch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * @Author Raymond Pittman | |
| * @Github: https://github.com/raymondpittman | |
| */ | |
| function download(url, filename) { | |
| fetch(url, { | |
| mode: 'no-cors' /*{mode:'cors'}*/ | |
| }).then((transfer) => { | |
| return transfer.blob(); | |
| }).then((bytes) => { | |
| let elm = document.createElement('a'); | |
| elm.href = URL.createObjectURL(bytes); | |
| elm.setAttribute('download', filename); | |
| elm.click() | |
| }).catch((error) => { | |
| console.log(error); | |
| }) | |
| } | |
| download('http://.zip', 'test.zip'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment