function saveFile(url) {
return new Promise(function(resolve, reject) {
var xhr= new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
resolve(xhr);
};
xhr.onerror = reject;
xhr.open('GET', url);
var jsons = cookieJson();
xhr.setRequestHeader('usertoken', jsons.usertoken);
xhr.setRequestHeader('username', jsons.username);
xhr.send();
}).then(function(xhr) {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
a.download = ''; // Set the file name.
a.style.display = 'none';
document.body.appendChild(a);
a.click();
return xhr;
});
}