1234567891011121314151617181920212223 |
- export default function downloadFile(url,fileName,changeState){
- changeState & changeState(true);
- let _url = "";
- if (url.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1)_url = url.split("https://view.officeapps.live.com/op/view.aspx?src=")[1];
- else _url = url;
- const x = new XMLHttpRequest();
- x.open("GET", _url, true);
- x.responseType = "blob";
- x.onload = function (e) {
- let content = x.response;
- let link = document.createElement("a");
- link.download = fileName;
- link.style.display = "none";
- let blob = new Blob([content]);
- link.href = URL.createObjectURL(blob);
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- changeState & changeState(false);
- }
- x.send()
- }
|