Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Last active November 16, 2018 06:39
Show Gist options
  • Select an option

  • Save andrIvash/833d41e0a0958db4ea8b62c0c0a150ef to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/833d41e0a0958db4ea8b62c0c0a150ef to your computer and use it in GitHub Desktop.
download file with a link
_onDownloadTaxonomyNowClick: function () {
var parsedURL = globals.rest.GET_TAXONOMY_FEED_FILE_URL.split("/"),
filename = parsedURL[parsedURL.length - 1],
linkElement = document.createElement("a");
request.get(globals.rest.GET_TAXONOMY_FEED_FILE_URL, {
"headers": {
"Content-Type": "application/xml"
},
"handleAs": "xml"
}).then(function (data) {
var blob = null,
objectURL = null;
if (data) {
try {
blob = new Blob([new XMLSerializer().serializeToString(data.documentElement)], {
type: "text/xml;charset=utf-8"
});
objectURL = URL.createObjectURL(blob);
if (navigator.msSaveBlob || navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
linkElement.setAttribute("href", objectURL);
linkElement.setAttribute("download", filename);
linkElement.style.display = "none";
document.body.appendChild(linkElement);
linkElement.click();
document.body.removeChild(linkElement);
}
message.success(l10n.saveFileSuccess);
} catch (error) {
console.error(error);
message.error(l10n.saveFileFailed);
}
} else {
console.error("request error");
message.error(l10n.saveFileFailed);
}
}, function (error) {
console.error(error);
message.error(l10n.saveFileFailed);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment