Created
July 24, 2018 09:38
-
-
Save DominikAngerer/dc9c7735021c13a4a05ee4752e3591ce to your computer and use it in GitHub Desktop.
This file contains 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
function forceDownload(blob, filename) { | |
var a = document.createElement('a'); | |
a.download = filename; | |
a.href = blob; | |
a.click(); | |
} | |
// Current blob size limit is around 500MB for browsers | |
function downloadResource(url, filename) { | |
if (!filename) | |
filename = url.split('\\').pop().split('/').pop() | |
url = url.replace('a.storyblok', 's3.amazonaws.com/a.storyblok') | |
fetch(url, { | |
headers: new Headers({ | |
'Origin': location.origin | |
}), | |
mode: 'cors' | |
}) | |
.then(response => response.blob()) | |
.then(blob => { | |
let blobUrl = window.URL.createObjectURL(blob); | |
forceDownload(blobUrl, filename); | |
}) | |
.catch(e => console.error(e)); | |
} | |
downloadResource('https:///a.storyblok.com/f/39898/2560x1438/b6646724e1/visual_editor.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment