From 585ad3e3541a8e83db039df59e42ab640f66c221 Mon Sep 17 00:00:00 2001 From: whycrzg <ruanzhigang@whycst.com> Date: 星期三, 07 四月 2021 10:39:00 +0800 Subject: [PATCH] 更新download接口 --- src/main/java/com/whyc/controller/ProjectManageController.java | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/whyc/controller/ProjectManageController.java b/src/main/java/com/whyc/controller/ProjectManageController.java index e2f1c82..90deccf 100644 --- a/src/main/java/com/whyc/controller/ProjectManageController.java +++ b/src/main/java/com/whyc/controller/ProjectManageController.java @@ -128,10 +128,18 @@ @GetMapping("/download") - @ApiOperation(notes = "闇�瑕佸湪鍦板潃鏍忔祴璇�",value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡涓嬭浇") - public Object download(HttpServletResponse response, @RequestParam String filePath,@RequestParam String fileName) { - Response<Object> result = new Response<>(); - File file = new File( filePath); + @ApiOperation(notes = "闇�瑕佸湪鍦板潃鏍忔祴璇� http://localhost:8090/projectManage/download?fileName=鐢宠涔�.pdf",value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡涓嬭浇") + public String download(HttpServletResponse response, @ApiParam(value = "鏂囦欢璺緞",required = true)@RequestParam String filePath) { + String fileName = ""; + if (filePath.length() > 10&&filePath.contains("/")) { //IP鍦板潃+鏂囦欢鍚� + int lastIndexOf = filePath.lastIndexOf("/"); + fileName = filePath.substring(lastIndexOf); + } else { + return "filePath is Error"; + } + + String projectPath = FileUtils.getProjectPath(); + File file = new File( projectPath+fileName); if (file.exists()) { try { fileName= new String(fileName.getBytes("gbk"), "ISO8859-1"); @@ -153,10 +161,12 @@ outputStream.write(buffer, 0, i); i = bis.read(buffer); } - return result.setMsg(1,"涓嬭浇鎴愬姛"); +// return result.setMsg(1,"涓嬭浇鎴愬姛"); + return "downloadSuccessful"; } catch (Exception e) { e.printStackTrace(); - return result.setMsg(0,"涓嬭浇澶辫触"); +// return result.setMsg(0,"涓嬭浇澶辫触"); + return "downloadFailed"; } finally { if (bis != null) { try { @@ -173,8 +183,9 @@ } } } + }else{ + return "fileDoesNotExist"; } - return result.setMsg(0,"鏂囦欢涓嶅瓨鍦�"); } -- Gitblit v1.9.1