Bladeren bron

修改文件上传逻辑

tianboguang 2 jaren geleden
bovenliggende
commit
3fde8da6e8
1 gewijzigde bestanden met toevoegingen van 23 en 1 verwijderingen
  1. 23 1
      src/main/java/com/fdkankan/contro/controller/SceneFileController.java

+ 23 - 1
src/main/java/com/fdkankan/contro/controller/SceneFileController.java

@@ -1,12 +1,18 @@
 package com.fdkankan.contro.controller;
 
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.contro.service.ISceneFileBuildService;
 import com.fdkankan.contro.vo.ResponseSceneFile;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.web.response.ResultData;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 
 /**
@@ -18,6 +24,9 @@ import java.io.IOException;
 public class SceneFileController{
 
     @Autowired
+    private FYunFileServiceInterface fYunFileService;
+
+    @Autowired
     private ISceneFileBuildService sceneFileBuildService;
 
     /**
@@ -58,5 +67,18 @@ public class SceneFileController{
         return sceneFileBuildService.rebuildScene(num,force);
     }
 
-
+    /**
+     * 上传文件
+     * @param file
+     * @return
+     */
+    @RequestMapping(value = "upload", method = RequestMethod.POST)
+    public ResultData uploadFile(String key, @RequestParam("file") MultipartFile file) throws Exception {
+        if(ObjectUtils.isEmpty(key) || ObjectUtils.isEmpty(file)){
+            log.error("参数有误!");
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        fYunFileService.uploadFile(file.getInputStream(),key.concat(File.separator).concat(file.getOriginalFilename()));
+        return ResultData.ok();
+    }
 }