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

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

 @RequestMapping(value="singleDocumentDownload", method = RequestMethod.POST)
 public void download(HttpServletResponse response, @RequestBody Map<String, Object> map){
    String fileName = null;
    String filePath = null;
    List<Document> 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);
  

猜你喜欢

转载自blog.csdn.net/yangli05287506/article/details/105489450