diff --git a/novel-admin/logs/debug.log b/novel-admin/logs/debug.log deleted file mode 100644 index 5ebdf85..0000000 --- a/novel-admin/logs/debug.log +++ /dev/null @@ -1,8 +0,0 @@ -2020-05-13 21:52:00,972 INFO (StartupInfoLogger.java:50)- Starting TestDemo on USER-20180729KA with PID 3532 (started by Administrator in E:\baseprojectparent\novel-plus\novel-admin) -2020-05-13 21:52:01,113 DEBUG (StartupInfoLogger.java:53)- Running with Spring Boot v2.0.1.RELEASE, Spring v5.0.5.RELEASE -2020-05-13 21:52:01,131 INFO (SpringApplication.java:663)- The following profiles are active: dev -2020-05-13 21:52:54,469 DEBUG (ApplicationContextRegister.java:29)- ApplicationContext registed-->org.springframework.web.context.support.GenericWebApplicationContext@5b529706: startup date [Wed May 13 21:52:01 CST 2020]; root of context hierarchy -2020-05-13 21:53:49,622 INFO (StartupInfoLogger.java:59)- Started TestDemo in 114.268 seconds (JVM running for 124.957) -2020-05-18 09:48:03,219 INFO (StartupInfoLogger.java:50)- Starting TestDemo on DESKTOP-CPCLUI6 with PID 13172 (started by 11797 in D:\gitee\novel-plus\novel-admin) -2020-05-18 09:48:03,223 DEBUG (StartupInfoLogger.java:53)- Running with Spring Boot v2.0.1.RELEASE, Spring v5.0.5.RELEASE -2020-05-18 09:48:03,227 INFO (SpringApplication.java:663)- The following profiles are active: dev diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java b/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java index b2fe3ee..d720343 100644 --- a/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java +++ b/novel-front/src/main/java/com/java2nb/novel/controller/FileController.java @@ -1,17 +1,32 @@ package com.java2nb.novel.controller; +import com.java2nb.novel.core.bean.ResultBean; import com.java2nb.novel.core.cache.CacheService; +import com.java2nb.novel.core.utils.Constants; import com.java2nb.novel.core.utils.RandomValidateCodeUtil; +import com.java2nb.novel.core.utils.RestTemplateUtil; +import com.java2nb.novel.core.utils.UUIDUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.Charsets; +import org.apache.http.client.utils.DateUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.imageio.ImageIO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import java.io.*; +import java.util.Date; +import java.util.Objects; /** * @author 11797 @@ -24,6 +39,9 @@ public class FileController { private final CacheService cacheService; + @Value("${pic.save.path}") + private String picSavePath; + /** * 生成验证码 */ @@ -44,5 +62,32 @@ public class FileController { } } + /** + * 文件上传 + */ + @ResponseBody + @PostMapping("/upload") + ResultBean upload(@RequestParam("file") MultipartFile file) { + Date currentDate = new Date(); + try { + String savePath = + Constants.LOCAL_PIC_PREFIX + DateUtils.formatDate(currentDate, "yyyy") + "/" + + DateUtils.formatDate(currentDate, "MM") + "/" + + DateUtils.formatDate(currentDate, "dd") ; + String oriName = file.getOriginalFilename(); + String saveFileName = UUIDUtil.getUUID32() + oriName.substring(oriName.lastIndexOf(".")); + File saveFile = new File( picSavePath + savePath, saveFileName); + if (!saveFile.getParentFile().exists()) { + saveFile.getParentFile().mkdirs(); + } + file.transferTo(saveFile); + return ResultBean.ok(savePath+"/"+saveFileName); + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResultBean.error(); + } + + } + } diff --git a/novel-front/src/main/resources/static/javascript/ajaxfileupload.js b/novel-front/src/main/resources/static/javascript/ajaxfileupload.js new file mode 100644 index 0000000..d7c56b6 --- /dev/null +++ b/novel-front/src/main/resources/static/javascript/ajaxfileupload.js @@ -0,0 +1,217 @@ +jQuery.extend({ + createUploadIframe: function(id, uri) + { + //create frame + var frameId = 'jUploadFrame' + id; + var iframeHtml = '