axios下载文件取不到content-disposition

编程知识 更新时间:2023-04-05 05:44:42

axios下载文件取不到content-disposition

axios 提交表单同时下载文件

  • 问题描述:
    直接访问url下载文件时是有Content-Dispositionheader的,使用axios时取不到该header。
  • 后台代码
 	@GetMapping("/exportConfig")
    public void exportConfig(@RequestParam("projectId") Integer projectId, HttpServletResponse response) throws Exception {
        logger.debug("access schedule exportConfig , projectId={}",projectId);
        String configStr=jobService.exportConfig(projectId);
        JobGroup jobGroup=jobService.getJobGroupByProjectId(projectId);
        String name = new String((jobGroup.getEnvName()+"_"+jobGroup.getProjectName()+".schedule").getBytes("utf-8"), "ISO-8859-1");
        response.setContentType("application/octet-stream; charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + name);
        OutputStream output = response.getOutputStream();
        output.write(configStr.getBytes());
    }
  • 解决办法
//响应时在响应头里添加 Access-Control-Expose-Headers 
 response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");

更多推荐

axios下载文件取不到content-disposition

本文发布于:2023-04-05 05:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/72d1e3d9d9c65a23625b3667d337e73d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   axios   disposition   content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 45080文章数
  • 14阅读数
  • 0评论数