网站建设实训课实训心得,公司内部网站建设奖励办法,iis7.5网站权限配置,住房和城乡建设部注册中心若依下载的逻辑是指定文件存储的路径#xff0c;在ruoyi-admin模块下的application.yml中配置路径结尾必须要加/或者\结尾。 他使用的是虚拟路径映射#xff0c;所以文件名必须是配置路径下真实的文件名。
若依采用的是流的方式#xff0c;前端必须要用bolb的方式去接收在ruoyi-admin模块下的application.yml中配置路径结尾必须要加/或者\结尾。 他使用的是虚拟路径映射所以文件名必须是配置路径下真实的文件名。
若依采用的是流的方式前端必须要用bolb的方式去接收然后保存成本地文件。 后端代码
参数一配置路径下真实的文件名。
参数二是否下载后删除false不删除。 AutowiredRuoYiConfig RuoYiConfig;GetMapping(/downloadZip)public void fileDownload(RequestParam String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {try {System.out.println(文件名称 fileName);if (!FileUtils.checkAllowDownload(fileName)) {throw new Exception(StringUtils.format(文件名称({})非法不允许下载。 , fileName));}String realFileName System.currentTimeMillis() fileName.substring(fileName.indexOf(_) 1);String filePath RuoYiConfig.getDownloadPath() fileName;response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);FileUtils.setAttachmentResponseHeader(response, realFileName);FileUtils.writeBytes(filePath, response.getOutputStream());if (delete) {FileUtils.deleteFile(filePath);}} catch (Exception e) {e.printStackTrace();System.out.format(下载文件失败, e);}} 前端代码
import request from /utils/requestexport const publishExportTemplateFile (res, name, type false) {let url;if (type) {url window.URL.createObjectURL(new Blob([res], {type: application/zip}));} else {url window.URL.createObjectURL(new Blob([res]));}// const url window.URL.createObjectURL(new Blob([res]));const link document.createElement(a);link.style.display none;link.href url;link.setAttribute(download, name);document.body.appendChild(link);link.click();document.body.removeChild(link);
}export function downloadFile(filePath) {request({url: /projectAch/pages/downloadZip,method: get,params: {fileName: filePath, delete: false},responseType: blob // 设置响应类型为 blob}).then(response {publishExportTemplateFile(response ,filePath);}).catch(error {console.error(Download file failed:, error);});
}