From 4f7ffd1dee67a50149b604d33410e11611117cd8 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 02 三月 2023 15:29:13 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/all/UploadAttachService.java | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/lf/server/service/all/UploadAttachService.java b/src/main/java/com/lf/server/service/all/UploadAttachService.java index df16264..0adeca6 100644 --- a/src/main/java/com/lf/server/service/all/UploadAttachService.java +++ b/src/main/java/com/lf/server/service/all/UploadAttachService.java @@ -148,22 +148,28 @@ public void download(String guid, boolean inline, HttpServletResponse res) { try { if (StringHelper.isEmpty(guid)) { - WebHelper.write2Page(res, NO_FILE); + WebHelper.writeStr2Page(res, NO_FILE); return; } AttachEntity entity = attachService.selectByGuid(guid); if (entity == null) { - WebHelper.write2Page(res, NO_FILE); + WebHelper.writeStr2Page(res, NO_FILE); return; } - String file = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); - WebHelper.download(file, entity.getName(), inline, res); + String filePath = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); + File file = new File(filePath); + if (!file.exists() || file.isDirectory()) { + String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "鏂囦欢涓嶅瓨鍦�")); + WebHelper.writeStr2Page(res, msg); + } + + WebHelper.download(filePath, entity.getName(), inline, res); } catch (Exception ex) { try { - String msg = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.ERROR, "鏂囦欢涓嬭浇鍑洪敊")); - WebHelper.write2Page(res, msg); + String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "鏂囦欢涓嬭浇鍑洪敊")); + WebHelper.writeStr2Page(res, msg); } catch (Exception e) { log.error(e.getMessage(), e); } -- Gitblit v1.9.3