张涛 1 year ago
parent
commit
7b426e71f5

+ 1
- 2
src/main/java/com/lyg/tools/common/FileUtil.java View File

6
 
6
 
7
 import java.io.File;
7
 import java.io.File;
8
 import java.io.FileOutputStream;
8
 import java.io.FileOutputStream;
9
-import java.io.IOException;
10
 import java.io.OutputStream;
9
 import java.io.OutputStream;
11
 import java.time.LocalDateTime;
10
 import java.time.LocalDateTime;
12
 import java.time.format.DateTimeFormatter;
11
 import java.time.format.DateTimeFormatter;
43
         // 相对路径 - 不包含 uploadPath
42
         // 相对路径 - 不包含 uploadPath
44
         String url = String.format("%s/%s/%s", appid, monthStr, newFileName);
43
         String url = String.format("%s/%s/%s", appid, monthStr, newFileName);
45
 
44
 
46
-        return new String[] { filePath, url };
45
+        return new String[]{filePath, url};
47
     }
46
     }
48
 
47
 
49
     // 上传目录
48
     // 上传目录

+ 6
- 13
src/main/java/com/lyg/tools/controller/UploadController.java View File

19
     @Autowired
19
     @Autowired
20
     FileUtil fileUtil;
20
     FileUtil fileUtil;
21
 
21
 
22
-    public static String getFileType(MultipartFile file) throws Exception {
23
-        String fileName = file.getOriginalFilename();
24
-        // 通过文件名获取文件后缀,并与MIME类型映射表对比获取文件类型
25
-        String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
26
-        // 这里可以扩展为查询MIME类型映射表
27
-        return fileSuffix;
28
-    }
29
 
22
 
30
     /**
23
     /**
31
      * 通用端上传文件
24
      * 通用端上传文件
25
+     *
32
      * @param projectId 应用Id
26
      * @param projectId 应用Id
33
      * @return
27
      * @return
34
      * @throws Exception
28
      * @throws Exception
35
      */
29
      */
36
-    @PostMapping("/upload/cms")
30
+    @PostMapping("/upload/{projectId}")
37
     public ResponseBean uploadAdmin(@RequestParam(value = "file") MultipartFile file,
31
     public ResponseBean uploadAdmin(@RequestParam(value = "file") MultipartFile file,
38
-                                    @PathVariable(value = "projectId") String projectId
39
-    ) throws Exception {
40
-        String fileType = getFileType(file);
32
+                                    @RequestParam(value = "fileType") String fileType,
33
+                                    @PathVariable(value = "projectId") String projectId) throws Exception {
41
 
34
 
42
         Map<String, Object> res = new HashMap<>();
35
         Map<String, Object> res = new HashMap<>();
43
         String fileName = file.getOriginalFilename();
36
         String fileName = file.getOriginalFilename();
55
      * @return
48
      * @return
56
      * @throws Exception
49
      * @throws Exception
57
      */
50
      */
58
-    @PostMapping("/upload/base64/{appid}")
51
+    @PostMapping("/upload/base64/{projectId}")
59
     public ResponseBean uploadBase64(
52
     public ResponseBean uploadBase64(
60
-            @PathVariable(value = "appid") String projectId,
53
+            @PathVariable(value = "projectId") String projectId,
61
             @RequestParam(value = "base64") String base64,
54
             @RequestParam(value = "base64") String base64,
62
             @RequestParam(value = "fileName", defaultValue = "unknown.jpg") String fileName
55
             @RequestParam(value = "fileName", defaultValue = "unknown.jpg") String fileName
63
     ) throws Exception {
56
     ) throws Exception {