Vue 实现上传文件下载文件功能(二进制流文件)
downloadFile(file) {
let fileType = lastSubstring(file.FILE_NAME, ".");
let blob = bs64toBlob(
file.FILE_CONTENT,
this.downloadBlobContentType[fileType.toLowerCase()]
); //file.FILE_CONTENT为Base64形式的二进制数据
if ("download" in document.createElement("a")) {
let elink = document.createElement("a");
elink.download = file.FILE_NAME;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href);
document.body.removeChild(elink);
} else {
navigator.msSaveBlob(blob, file.FILE_NAME);
}
},