Skip to content

Instantly share code, notes, and snippets.

@fhdez
Created August 2, 2018 17:50
Show Gist options
  • Save fhdez/a78205a955c6ce1b243c4523002c0cef to your computer and use it in GitHub Desktop.
Save fhdez/a78205a955c6ce1b243c4523002c0cef to your computer and use it in GitHub Desktop.
vm.downloadcsv = function() {
$http({
method: 'GET',
url: '/api/v1/activities/record/'+vm.query.domain.id+'/csv',
params: {
'datesince': vm.query.datesince,
'dateto':vm.query.dateto,
'verbs':vm.query.verb
},
responseType: 'arraybuffer'
}).success(function (data, status, headers) {
headers = headers();
var filename = headers['x-filename'];
var contentType = headers['content-type'];
var linkElement = document.createElement('a');
try {
var blob = new Blob([data], { type: contentType });
var url = window.URL.createObjectURL(blob);
linkElement.setAttribute('href', url);
linkElement.setAttribute("download", filename);
var clickEvent = new MouseEvent("click", {
"view": window,
"bubbles": true,
"cancelable": false
});
linkElement.dispatchEvent(clickEvent);
} catch (ex) {
console.log(ex);
}
}).error(function (data) {
console.log(data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment