Last active
November 24, 2017 10:08
-
-
Save drugoi/35848dae479999b385763f8d1e86eaca 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
const download = (fileName, mimeType, fileData) => { | |
if (window.navigator.msSaveOrOpenBlob === undefined) { | |
const e = document.createElement('a'); | |
const href = `data:${mimeType};base64,${fileData}`; | |
e.setAttribute('href', href); | |
e.setAttribute('download', fileName); | |
document.body.appendChild(e); | |
e.click(); | |
document.body.removeChild(e); | |
} else { | |
const charCodeArr = new Array(fileData.length); | |
for (let i = 0; i < fileData.length; ++i) { | |
const charCode = fileData.charCodeAt(i); | |
charCodeArr[i] = charCode; | |
} | |
const blob = new Blob([new Uint8Array(charCodeArr)], { | |
type: mimeType | |
}); | |
window.navigator.msSaveOrOpenBlob(blob, fileName); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment