vue+stringboot实现下载

拜拜、爱过 提交于 2020-02-26 00:51:18

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()
        })
      }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!