Skip to content

Instantly share code, notes, and snippets.

@DominikAngerer
Created July 24, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikAngerer/dc9c7735021c13a4a05ee4752e3591ce to your computer and use it in GitHub Desktop.
Save DominikAngerer/dc9c7735021c13a4a05ee4752e3591ce to your computer and use it in GitHub Desktop.
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