dengsixing 8 月之前
父節點
當前提交
093b5b2794

+ 42 - 1
src/main/java/com/fdkankan/scene/controller/TestController.java

@@ -1,13 +1,25 @@
 package com.fdkankan.scene.controller;
 
+import cn.hutool.core.collection.CollUtil;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.rabbitmq.util.RabbitMqProducer;
 import com.fdkankan.web.response.ResultData;
+import com.obs.services.ObsClient;
+import com.obs.services.internal.utils.Mimetypes;
+import com.obs.services.model.AccessControlList;
+import com.obs.services.model.ObjectMetadata;
+import com.obs.services.model.PutObjectRequest;
+import org.apache.http.HttpHeaders;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.activation.MimeType;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * <p>
  * TODO
@@ -27,7 +39,36 @@ public class TestController {
 
     @GetMapping("/test")
     public ResultData test(){
-        return ResultData.ok(fYunFileService.fileExist("scene_result_data/KK-t-JCaoqtvy7AO/caches/images"));
+        //obsv3.scrb-cd-1.sichuandaily.com.cn
+        Map<String, Object> headers = new HashMap<>();
+        headers.put(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
+        String filePath = "C:\\Users\\dsx\\Downloads\\screencap";
+        ObsClient obsClient = new ObsClient("AFMVGM5CPSHHQ7UPG3DO", "IUYocj8qgixoDxhj3JIVKXtyBV3lGDJBDFgRhO21", "obsv3.scrb-cd-1.sichuandaily.com.cn");
+
+        File file = new File(filePath);
+        ObjectMetadata metadata = new ObjectMetadata();
+        if (CollUtil.isNotEmpty(headers)) {
+            metadata.setContentType("application/octet-stream");
+//            metadata.setContentEncoding(headers.get("Content-Encoding"));
+            metadata.setOriginalHeaders(headers);
+        }else{
+            if (filePath.contains(".jpg")) {
+                metadata.setContentType("image/jpeg");
+            }
+            if (filePath.contains(".mp4")) {
+                metadata.setContentType("video/mp4");
+            }
+            if (filePath.contains(".mp3")) {
+                metadata.setContentType("audio/mp3");
+            }
+        }
+
+        PutObjectRequest putObjectRequest = new PutObjectRequest("djqk-vr", "downloads/scene/KJ-t-fTL2wiEjeMS/tour/screencap.mp4", file);
+        putObjectRequest.setMetadata(metadata);
+        putObjectRequest.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
+        obsClient.putObject("djqk-vr", "downloads/scene/KJ-t-fTL2wiEjeMS/tour/screencap.mp4", file, metadata);
+
+        return ResultData.ok();
     }
 
 }

+ 8 - 3
src/main/java/com/fdkankan/scene/service/impl/DownloadTourVideoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fdkankan.scene.service.impl;
 
 import cn.hutool.core.exceptions.ExceptionUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.UUID;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -32,7 +33,7 @@ import org.springframework.web.multipart.MultipartFile;
  * 导览视频转换记录表 服务实现类
  * </p>
  *
- * @author 
+ * @author
  * @since 2022-10-12
  */
 @Service
@@ -104,7 +105,8 @@ public class DownloadTourVideoServiceImpl extends ServiceImpl<IDownloadTourVideo
 
         String destPath = null;
         try {
-            String destFileName = UUID.randomUUID().toString() + ".mp4";
+            String uuid = UUID.randomUUID().toString();
+            String destFileName = uuid + ".mp4";
             destPath = ConstantFilePath.SCENE_V4_PATH + downloadTourVideo.getNum() + "/tour/" + destFileName;
             File destFile = new File(destPath);
             if(!destFile.getParentFile().exists()){
@@ -113,10 +115,13 @@ public class DownloadTourVideoServiceImpl extends ServiceImpl<IDownloadTourVideo
             String srcPath = downloadTourVideo.getLocalPath();
             CreateObjUtil.formatMp4(srcPath, destPath);
             //上传到oss
+            //obs对MP4文件设置application/octet-stream不生效,所以这里复制一份不带扩展名的文件上传,obs会默认为application/octet-stream
+            String destPathNoExtName = ConstantFilePath.SCENE_V4_PATH + downloadTourVideo.getNum() + "/tour/" + uuid;
+            FileUtil.copy(destPath, destPathNoExtName, true);
             String ossPath = String.format(UploadFilePath.DOWNLOADS_TOUR_VIDEO, downloadTourVideo.getNum()) + downloadTourVideo.getFileName();
             Map<String, String> headers = new HashMap<>();
             headers.put(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
-            fYunFileService.uploadFile(bucket, destPath, ossPath, headers);
+            fYunFileService.uploadFile(bucket, destPathNoExtName, ossPath, headers);
             downloadTourVideo.setDownloadPath(ossPath);
             downloadTourVideo.setState(1);
             this.updateById(downloadTourVideo);