二进制流文件上传下载( springboot+vue)

一、springboot + vue文件下载
1、后端代码

 @RequestMapping(value="singleDocumentDownload", method = RequestMethod.POST)
 public void download(HttpServletResponse response, @RequestBody Map map){
    String fileName = null;
    String filePath = null;
    List documentList = documentMapper.searchDocPath(String.valueOf(map.get("docNo")));
    if(null != documentList && documentList.size() > 0){
        for(Document document : documentList){
            filePath = document.getDocPath();
            fileName = document.getDocName();
        }
    }
    File file = new File(filePath);
    // 创建输入对象
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    // 设置相关格式
    response.setContentType("application/force-download");
    // 设置下载后的文件名以及header
    response.addHeader("Content-disposition", "attachment;fileName=" + fileName);
  

你可能感兴趣的:(springboot)