Created
August 2, 2018 17:50
-
-
Save fhdez/a78205a955c6ce1b243c4523002c0cef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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