NutzCN Logo
问答 使用@ok(raw)下载文件时 ,无法下载,直接打开了文件,如何处理
发布于 1802天前 作者 DIAAA 1693 次浏览 复制 上一个帖子 下一个帖子
标签:
 @POST
    @At("/down")
    @Ok("raw")
    public File download(HttpServletRequest request) throws UnsupportedEncodingException {
        File file = new File("name");
        if(file.exists() && file.isFile()){
            return file;
        }
        return null;
    }
3 回复
    @At("/down")
    @Ok("raw")
    public File download(HttpServletRequest request, HttpServletResponse response) throws IOException {

        File file = new File("pathname");
        response.reset();
        response.setHeader("Content-Disposition", "attachment; filename=animate.css");
//        response.addHeader("Content-Length", "" + file);
        response.setContentType("application/octet-stream; charset=UTF-8");
        if(file.exists() && file.isFile()){
            return file;
        }
        return null;
    }
 this.$axios.get(API_SYS_USER_EXPORT, {
        responseType: 'blob',
        params: this.pageData
      }).then(res => {
        const url = window.URL.createObjectURL(new Blob([res.data]))
        const link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', 'sys_user.xlsx')
        document.body.appendChild(link)
        link.click()
      })
添加回复
请先登陆
回到顶部