张延森 3 years ago
parent
commit
bea11d61a8

+ 54
- 28
src/main/java/com/yunzhi/marketing/controller/CommonController.java View File

@@ -56,23 +56,31 @@ public class CommonController extends BaseController {
56 56
     @PostMapping("/{plat}/image")
57 57
     public ResponseBean uploadImage(@PathVariable String plat, @RequestParam("file") MultipartFile multipartFile) {
58 58
         try {
59
-            // 本地保存的文件夹
60
-            String format = sdf.format(new Date());
61
-            File folder = new File(FILE_PATH + format);
62
-            if(!folder.isDirectory()) {
63
-                folder.mkdirs();
64
-            }
65
-            // 新文件夹
66
-            String oldName = multipartFile.getOriginalFilename();
67
-            String newName = UUID.randomUUID().toString() +
68
-                    oldName.substring(oldName.lastIndexOf("."));
69
-
70
-            // 文件保存操作
71
-            multipartFile.transferTo(new File(folder, newName));
72
-            return ResponseBean.success("/file/"+ format + newName);
59
+            String folder = FILE_PATH + sdf.format(new Date());
60
+            String img = AliOSSUtils.putObject(multipartFile, folder);
61
+            return ResponseBean.success(img);
73 62
         } catch (IOException e) {
74 63
             return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
75 64
         }
65
+
66
+//        try {
67
+//            // 本地保存的文件夹
68
+//            String format = sdf.format(new Date());
69
+//            File folder = new File(FILE_PATH + format);
70
+//            if(!folder.isDirectory()) {
71
+//                folder.mkdirs();
72
+//            }
73
+//            // 新文件夹
74
+//            String oldName = multipartFile.getOriginalFilename();
75
+//            String newName = UUID.randomUUID().toString() +
76
+//                    oldName.substring(oldName.lastIndexOf("."));
77
+//
78
+//            // 文件保存操作
79
+//            multipartFile.transferTo(new File(folder, newName));
80
+//            return ResponseBean.success("/file/"+ format + newName);
81
+//        } catch (IOException e) {
82
+//            return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
83
+//        }
76 84
     }
77 85
 
78 86
 
@@ -152,20 +160,9 @@ public class CommonController extends BaseController {
152 160
         Map<String, String> result = new HashMap<>();
153 161
 
154 162
         try {
155
-            // 本地保存的文件夹
156
-            String format = sdf.format(new Date());
157
-            File folder = new File(FILE_PATH + format);
158
-            if(!folder.isDirectory()) {
159
-                folder.mkdirs();
160
-            }
161
-            // 新文件夹
162
-            String oldName = multipartFile.getOriginalFilename();
163
-            String newName = UUID.randomUUID().toString() +
164
-                    oldName.substring(oldName.lastIndexOf("."));
165
-
166
-            // 文件保存操作
167
-            multipartFile.transferTo(new File(folder, newName));
168
-            String img = "/file/"+ format + newName;
163
+            String folder = FILE_PATH + sdf.format(new Date());
164
+            String img = AliOSSUtils.putObject(multipartFile, folder);
165
+
169 166
             result.put("name", StringUtils.ifNull(multipartFile.getOriginalFilename(), multipartFile.getName()));
170 167
             result.put("status", "done");
171 168
             result.put("thumbUrl", img + "?x-oss-process=style/thumbnail");
@@ -177,6 +174,35 @@ public class CommonController extends BaseController {
177 174
         }
178 175
 
179 176
         return result;
177
+
178
+//        Map<String, String> result = new HashMap<>();
179
+//
180
+//        try {
181
+//            // 本地保存的文件夹
182
+//            String format = sdf.format(new Date());
183
+//            File folder = new File(FILE_PATH + format);
184
+//            if(!folder.isDirectory()) {
185
+//                folder.mkdirs();
186
+//            }
187
+//            // 新文件夹
188
+//            String oldName = multipartFile.getOriginalFilename();
189
+//            String newName = UUID.randomUUID().toString() +
190
+//                    oldName.substring(oldName.lastIndexOf("."));
191
+//
192
+//            // 文件保存操作
193
+//            multipartFile.transferTo(new File(folder, newName));
194
+//            String img = "/file/"+ format + newName;
195
+//            result.put("name", StringUtils.ifNull(multipartFile.getOriginalFilename(), multipartFile.getName()));
196
+//            result.put("status", "done");
197
+//            result.put("thumbUrl", img + "?x-oss-process=style/thumbnail");
198
+//            result.put("url", img);
199
+//
200
+//        } catch (IOException e) {
201
+//            result.put("status", "error");
202
+//            result.put("message", e.getMessage());
203
+//        }
204
+
205
+//        return result;
180 206
     }
181 207
 
182 208
     @PostMapping("{plat}/captcha")

+ 1
- 1
src/main/resources/application-dev.yml View File

@@ -92,4 +92,4 @@ fadada:
92 92
   redirectUrl: "https://dev.fangdeal.cn/other/redirect.html"
93 93
 # file path
94 94
 file:
95
-  path: D:\images\
95
+  path: /images/

+ 1
- 1
src/main/resources/application-prod.yml View File

@@ -97,4 +97,4 @@ fadada:
97 97
   redirectUrl: "https://wx.fangdeal.cn/other/redirect.html"
98 98
 # file path
99 99
 file:
100
-  path: /yunpan/dev/files/
100
+  path: /images/