张涛 1 年之前
父節點
當前提交
7b426e71f5

+ 1
- 2
src/main/java/com/lyg/tools/common/FileUtil.java 查看文件

@@ -6,7 +6,6 @@ import org.springframework.web.multipart.MultipartFile;
6 6
 
7 7
 import java.io.File;
8 8
 import java.io.FileOutputStream;
9
-import java.io.IOException;
10 9
 import java.io.OutputStream;
11 10
 import java.time.LocalDateTime;
12 11
 import java.time.format.DateTimeFormatter;
@@ -43,7 +42,7 @@ public class FileUtil {
43 42
         // 相对路径 - 不包含 uploadPath
44 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 查看文件

@@ -19,25 +19,18 @@ public class UploadController {
19 19
     @Autowired
20 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 26
      * @param projectId 应用Id
33 27
      * @return
34 28
      * @throws Exception
35 29
      */
36
-    @PostMapping("/upload/cms")
30
+    @PostMapping("/upload/{projectId}")
37 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 35
         Map<String, Object> res = new HashMap<>();
43 36
         String fileName = file.getOriginalFilename();
@@ -55,9 +48,9 @@ public class UploadController {
55 48
      * @return
56 49
      * @throws Exception
57 50
      */
58
-    @PostMapping("/upload/base64/{appid}")
51
+    @PostMapping("/upload/base64/{projectId}")
59 52
     public ResponseBean uploadBase64(
60
-            @PathVariable(value = "appid") String projectId,
53
+            @PathVariable(value = "projectId") String projectId,
61 54
             @RequestParam(value = "base64") String base64,
62 55
             @RequestParam(value = "fileName", defaultValue = "unknown.jpg") String fileName
63 56
     ) throws Exception {