From 3df8c0bb68eb5f3ae477abd5a45700b856c48b9d Mon Sep 17 00:00:00 2001
From: 胡仁荣 <897853850@qq.com>
Date: 星期四, 24 八月 2023 10:56:24 +0800
Subject: [PATCH] oss分块上传

---
 src/main/java/com/qxueyou/scc/controller/HweiYunOBSController.java |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/qxueyou/scc/controller/HweiYunOBSController.java b/src/main/java/com/qxueyou/scc/controller/HweiYunOBSController.java
index 9c8516a..d076b5e 100644
--- a/src/main/java/com/qxueyou/scc/controller/HweiYunOBSController.java
+++ b/src/main/java/com/qxueyou/scc/controller/HweiYunOBSController.java
@@ -9,9 +9,11 @@
 import com.aliyun.oss.OSSException;
 import com.obs.services.exception.ObsException;
 import com.obs.services.model.PutObjectResult;
+import com.qxueyou.scc.base.model.CacheConstants;
 import com.qxueyou.scc.base.model.FileMeta;
 import com.qxueyou.scc.base.model.Result;
 import com.qxueyou.scc.base.util.ClientUtils;
+import com.qxueyou.scc.base.util.UUIDUtils;
 import com.qxueyou.scc.teach.res.service.HweiYunOBSService;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
@@ -28,6 +30,7 @@
 import java.io.InputStream;
 import java.net.URLEncoder;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -51,10 +54,21 @@
         if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
             return null;
         }
-//        if (FileUtil.isEmpty(file)) {
-//            return new Result(false,"鏂囦欢涓虹┖");
-//        }
-        final List<FileMeta> test = hweiYunOBSService.fileUpload(file, file.getOriginalFilename());
+        String originalFilename = file.getOriginalFilename();
+        String substring = originalFilename.substring(originalFilename.indexOf(".")+1);
+
+        StringBuffer path=new StringBuffer();
+        //璇嗗埆鏂囦欢鍚庣紑鏍煎紡锛岃幏鍙栧搴旂殑鏂囦欢瀛樺偍璺緞
+        String pathFile = CacheConstants.fileFormatMap.get(substring.toUpperCase(Locale.ROOT));
+        if (StringUtils.isEmpty(pathFile)) {//濡傛灉涓虹┖鍒欎笂浼犲埌榛樿瀛樺偍鏂囦欢澶�
+            path.append(CacheConstants.GUANGXI_ACQUIESCE);
+        }else{
+            path.append(pathFile);
+        }
+        String uuid = UUIDUtils.UUID();
+        //灏嗘枃浠堕噸鏂板懡鍚嶏紝闃叉鍑虹幇閲嶅悕瑕嗙洊
+        String newFilename=uuid.concat(file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")));
+        final List<FileMeta> test = hweiYunOBSService.fileUpload(file,path.append(newFilename).toString());
 //        return ResponseVO.ok("鎵ц鎴愬姛",test);
         return test;
     }
@@ -112,8 +126,20 @@
 
         //濡傛灉MD5鐨勫搴旀枃浠跺瓨鍦ㄥ垯鐩存帴杩斿洖
 //        Result result = fileService.checkMd5(md5,fileName);
+        String substring = fileName.substring(fileName.indexOf(".")+1);
 
-        return hweiYunOBSService.initUploadChunk(identifier.concat(ClientUtils.getUserId()), fileName,md5);
+        StringBuffer path=new StringBuffer();
+        //璇嗗埆鏂囦欢鍚庣紑鏍煎紡锛岃幏鍙栧搴旂殑鏂囦欢瀛樺偍璺緞
+        String pathFile = CacheConstants.fileFormatMap.get(substring.toUpperCase(Locale.ROOT));
+        if (StringUtils.isEmpty(pathFile)) {//濡傛灉涓虹┖鍒欎笂浼犲埌榛樿瀛樺偍鏂囦欢澶�
+            path.append(CacheConstants.GUANGXI_ACQUIESCE);
+        }else{
+            path.append(pathFile);
+        }
+        String uuid = UUIDUtils.UUID();
+        //灏嗘枃浠堕噸鏂板懡鍚嶏紝闃叉鍑虹幇閲嶅悕瑕嗙洊
+        String newFilename=uuid.concat(String.valueOf(fileName.lastIndexOf(".")));
+        return hweiYunOBSService.initUploadChunk(identifier.concat(ClientUtils.getUserId()),path.append(newFilename).toString(),md5);
 
     }
 

--
Gitblit v1.8.0