Преглед изворни кода

添加上传文件的接口

tianboguang пре 2 година
родитељ
комит
f7b944b2d9
1 измењених фајлова са 38 додато и 0 уклоњено
  1. 38 0
      src/main/java/com/fdkankan/contro/controller/ApiFileController.java

+ 38 - 0
src/main/java/com/fdkankan/contro/controller/ApiFileController.java

@@ -0,0 +1,38 @@
+package com.fdkankan.contro.controller;
+
+
+import com.fdkankan.contro.common.Result;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/file/")
+public class ApiFileController {
+
+    @Autowired
+    private FYunFileServiceInterface fYunFileService;
+    /**
+     * 上传文件
+     * @param file
+     * @return
+     */
+    @RequestMapping(value = "upload", method = RequestMethod.POST)
+    public Result uploadFile(String key, @RequestParam("file") MultipartFile file) throws Exception {
+        if(ObjectUtils.isEmpty(key) || ObjectUtils.isEmpty(file)){
+            log.error("参数有误!");
+            return Result.failure("参数有误!");
+        }
+        fYunFileService.uploadFile(file.getInputStream(),key);
+        return Result.success();
+    }
+}