java
@GetMapping("download")
public void downloadPhylo(@PathVariable String uuid, HttpServletRequest request, HttpServletResponse response) {
try (InputStream inputStream = new FileInputStream("E:\\zhy\\zhy.txt");
ServletOutputStream servletOutputStream = response.getOutputStream()) {
response.setContentType("application/octet-stream");
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.addHeader("Pragma", "no-cache");
IOUtils.copy(inputStream, servletOutputStream);
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
}
}
vue
zhyDownload() {
const loading = this.$loading({
lock: true,
text: '结果下载中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
// 封装下载的方法
downloadEvolutionary().then(res => {
loading.close()
const url = window.URL.createObjectURL(new Blob([res.data]))
const link = document.createElement('a')
link.href = url
link.setAttribute('download', 'in.aln.fa')
document.body.appendChild(link)
link.click()
})
}
来源:CSDN
作者:会迟到但不会缺席
链接:https://blog.csdn.net/qq_27721169/article/details/104495789