https://blog.csdn.net/qq_35867245/article/details/84325385vue
第一步:在application.yml中配置附件要上传的路径(此路径也是下载的路径)java
***:windows路径和linux的路径是不一样的,定义路径时要仔细(存放路劲本身定义便可)linux
第二步:在服务端要调用接口所在的类(通常为控制层controller)定义一个变量spring
第三步:上传附件的代码:docker
本人碰见的坑:部署时vue+springboot分离部署windows
linux中的文件上传路径是java容器内部的路径,要进入容器内部才能看到,springboot
进入java容器内部命令时bash
docker exec -it 容器名 bashapp
ExcelReaderUtil工具public static void download(String path, HttpServletResponse response) {工具
try { if(StringUtils.isNotBlank(path)){ File file = new File(path); // 取得文件名。 String fileName = file.getName(); // 以流的形式下载文件。 InputStream fis = new BufferedInputStream(new FileInputStream(path)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); // 清空response response.reset(); String uncod=URLDecoder.decode(fileName,"UTF-8"); fileName = new String(uncod.getBytes("UTF-8"), "iso-8859-1"); response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(fileName))); // 设置response的Header response.addHeader("Content-Length", "" + file.length()); OutputStream toClient = new BufferedOutputStream( response.getOutputStream()); toClient.write(buffer); toClient.flush(); toClient.close(); } // path是指欲下载的文件的路径。 } catch (IOException ex) { ex.printStackTrace(); } } ---------------------