From 8f781f3cb17187a7ee58f41632c25fbb2aa81cc7 Mon Sep 17 00:00:00 2001 From: linzhijie <19970921lzj> Date: 星期二, 16 三月 2021 19:57:24 +0800 Subject: [PATCH] 补充环境配置 --- src/main/java/com/ots/project/common/CommonController.java | 73 ++++++++++++++++++++++++------------ 1 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/ots/project/common/CommonController.java b/src/main/java/com/ots/project/common/CommonController.java index fdbe8a0..18163f0 100644 --- a/src/main/java/com/ots/project/common/CommonController.java +++ b/src/main/java/com/ots/project/common/CommonController.java @@ -1,4 +1,5 @@ package com.ots.project.common; + import com.ots.common.utils.file.FileUploadUtils; import com.ots.common.utils.file.FileUtils; import com.ots.framework.config.EssConfig; @@ -12,24 +13,38 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +/** + * 閫氱敤璇锋眰澶勭悊 + * + * @author ots + */ @Controller public class CommonController { private static final Logger log = LoggerFactory.getLogger(CommonController.class); + @Autowired private ServerConfig serverConfig; - + + /** + * 閫氱敤涓嬭浇璇锋眰 + * + * @param fileName 鏂囦欢鍚嶇О + * @param delete 鏄惁鍒犻櫎 + */ @GetMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { try { - - - - + //鍏堟敞閲婃帀鐪嬬湅锛屽洜涓烘病鏈夊彂鍏堟湰绯荤粺鐨勪笟鍔$殑浠讳綍鎰忎箟 +// if (!FileUtils.isValidFilename(fileName)) { +// throw new Exception(StringUtils.format("鏂囦欢鍚嶇О({})闈炴硶锛屼笉鍏佽涓嬭浇銆� ", fileName)); +// } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String filePath = EssConfig.getDownloadPath() + fileName; + response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", @@ -42,14 +57,17 @@ log.error("涓嬭浇鏂囦欢澶辫触", e); } } - + + /** + * 閫氱敤涓婁紶璇锋眰 + */ @PostMapping("/common/upload") @ResponseBody public AjaxResult uploadFile(MultipartFile file) throws Exception { try { - + // 涓婁紶鏂囦欢璺緞 String filePath = EssConfig.getUploadPath(); - + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О String fileName = FileUploadUtils.upload(filePath, file); String url = serverConfig.getUrl() + fileName; AjaxResult ajax = AjaxResult.success(); @@ -60,31 +78,36 @@ return AjaxResult.error(e.getMessage()); } } - + /** + * 涓婁紶鍥剧墖鏈嶅姟鍣� + * /common/images 杩欓噷璇锋眰鐨勮繛鎺ユ槸images锛屼綘鐨勬枃浠跺す涔熻鍙玦mages + */ @PostMapping("/common/images") @ResponseBody public AjaxResult upImage(MultipartFile file) throws Exception { try { - + // 涓婁紶鏂囦欢璺緞 String filePath = EssConfig.getUploadImagePath(); - + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О String fileName = FileUploadUtils.upload(filePath, file); - + //String url = serverConfig.getUrl() + fileName; String url = fileName.replaceFirst("/profile/images", EssConfig.getImagePath()); - - - - - - - - - - - - - + //1銆佸厛鍘嬬缉鍑轰竴涓柊鐨� + // filePath = "/Users/shawnli/Downloads/images" + // fileName = "/profile/images/2019/12/19/aba5e2f850edf254a9e5b2a35c50089a.png" +// // url = "http://localhost:8090/profile/images/2019/12/19/aba5e2f850edf254a9e5b2a35c50089a.png" +// String filePathOriginal = fileName.replaceFirst("/profile/images", filePath); +// String fileNew = filePathOriginal + "."+filePathOriginal.substring(filePathOriginal.lastIndexOf(".") + 1); +// PicUtils.commpressPicForScale(filePathOriginal, fileNew, 20, 0.5); +// +// //2銆佸垹闄ゆ棫鐨� +// File fileOper = new File(filePathOriginal); +// fileOper.delete(); +// +// //3銆佸懡鍚嶆柊鐨勪负鏃х殑鍚嶅瓧 +// File fileNewOper = new File(fileNew); +// fileNewOper.renameTo(new File(filePathOriginal)); AjaxResult ajax = AjaxResult.success(); ajax.put("fileName", fileName); -- Gitblit v1.9.1