Browse Source

图片上传优化配置

wanxl 1 year ago
parent
commit
95a64cf9b1

+ 6 - 3
src/main/java/com/template/controller/UploadServlet.java

@@ -22,9 +22,12 @@ import java.nio.file.Files;
 @RequestMapping("/auto/upload")
 @RequestMapping("/auto/upload")
 public class UploadServlet {
 public class UploadServlet {
 
 
-    @Value("${image-url}")
+    @Value("${image.url}")
     private String imageUrl;
     private String imageUrl;
 
 
+    @Value("${image.path}")
+    private String imagePath;
+
     @PostMapping("/save")
     @PostMapping("/save")
     protected CommonResult doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     protected CommonResult doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // 获取文件内容
         // 获取文件内容
@@ -34,8 +37,8 @@ public class UploadServlet {
         String fileNameWithPath = FileUtil.getFileNameWithPath() + ".jpg";
         String fileNameWithPath = FileUtil.getFileNameWithPath() + ".jpg";
 //        FileUtil.makeDirs(fileNameWithPath, "E://image3");
 //        FileUtil.makeDirs(fileNameWithPath, "E://image3");
 //        String imgFilePath = "E://image3/" + fileNameWithPath;
 //        String imgFilePath = "E://image3/" + fileNameWithPath;
-        FileUtil.makeDirs(fileNameWithPath, "/usr/local/nginx/html/image");
-        String imgFilePath = "/usr/local/nginx/html/image/" + fileNameWithPath;
+        FileUtil.makeDirs(fileNameWithPath, imagePath);
+        String imgFilePath = imagePath+"/" + fileNameWithPath;
 
 
 //        上传图片
 //        上传图片
         Files.copy(fileContent,new File(imgFilePath).toPath());
         Files.copy(fileContent,new File(imgFilePath).toPath());

+ 3 - 1
src/main/resources/application-dev.yml

@@ -127,4 +127,6 @@ wechat:
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
 #图片上传地址
 #图片上传地址
-image-url: https://chtech.ncjti.edu.cn/hotel/image/
+image:
+  url: https://chtech.ncjti.edu.cn/hotel/image/
+  path: /usr/local/nginx/html/image

+ 3 - 1
src/main/resources/application-prod.yml

@@ -111,4 +111,6 @@ wechat:
       apiKey: chuanghaikeji2021chuanghaikeji20
       apiKey: chuanghaikeji2021chuanghaikeji20
       domain: http://73j8db.natappfree.cc  #回调地址
       domain: http://73j8db.natappfree.cc  #回调地址
 #图片上传地址
 #图片上传地址
-image-url: https://chtech.ncjti.edu.cn/hotel/image/
+image:
+  url: https://chtech.ncjti.edu.cn/hotel/image/
+  path: /usr/local/nginx/html/image

+ 3 - 1
src/main/resources/application-test.yml

@@ -132,4 +132,6 @@ wechat:
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
 #图片上传地址
 #图片上传地址
-image-url: https://chtech.ncjti.edu.cn/testingServer/image/
+image:
+  url: https://chtech.ncjti.edu.cn/testingServer/image/
+  path: /home/nginx/html/image

+ 3 - 1
src/main/resources/application.yml

@@ -124,4 +124,6 @@ wechat:
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       secret: 18e17f97e674e1c03fc255f12d12ca4d
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
       serialNum: 61A33563F6158C1B921A27A23A4E94E963DD53DD
 #图片上传地址
 #图片上传地址
-image-url: https://chtech.ncjti.edu.cn/hotel/image/
+image:
+  url: https://chtech.ncjti.edu.cn/hotel/image/
+  path: /usr/local/nginx/html/image