Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Last active August 21, 2016 17:56
Show Gist options
  • Save fakenickels/9db117ec09162ea02075717a75ab28ee to your computer and use it in GitHub Desktop.
Save fakenickels/9db117ec09162ea02075717a75ab28ee to your computer and use it in GitHub Desktop.
Download a file from the server with fetch HTML5 API and FileSaver.js
function downloadFromRoute({url, data, filename}){
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'text/json',
},
})
.then(response => response.blob())
.then(blob => saveAs(blob, filename))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment