Skip to content

Instantly share code, notes, and snippets.

@odirleiborgert
Forked from 11joselu/fileUtils.js
Created June 15, 2017 13:46
Show Gist options
  • Save odirleiborgert/2c2c799d3e7dbaac4fcc1d548891d4b2 to your computer and use it in GitHub Desktop.
Save odirleiborgert/2c2c799d3e7dbaac4fcc1d548891d4b2 to your computer and use it in GitHub Desktop.
Donwload File - Vue.js 2.x
export function getFile(response) {
var result = document.createElement('a');
var contentDisposition = response.headers.get('Content-Disposition') || '';
var filename = contentDisposition.split('filename=')[1];
filename = filename.replace(/"/g,"")
return response.blob()
.then(function(data) {
result.href = window.URL.createObjectURL(data);
result.target = '_self';
result.download = filename;
return result;
})
}
import * as fileUtil from '../fileUtils';
this.$http.post('/generate', data)
.then(fileUtil.getZIPData)
.then((link) => {
link.click();
})
.catch((err) => {
console.log(err)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment