Last active
November 16, 2018 06:39
-
-
Save andrIvash/833d41e0a0958db4ea8b62c0c0a150ef to your computer and use it in GitHub Desktop.
download file with a link
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
| _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