Pārlūkot izejas kodu

导览视频转换下载

dengsixing 2 gadi atpakaļ
vecāks
revīzija
256fb8a2e0

+ 5 - 5
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneEditController.java

@@ -463,11 +463,6 @@ public class SceneEditController extends BaseController {
         return sceneProService.saveRoam(param);
     }
 
-    @PostMapping(value = "/downloadRoamVideo")
-    public void tranferRoam(@RequestParam("file") MultipartFile file) throws Exception {
-        sceneUploadService.formatMp4(file, this.response);
-    }
-
     /**
      * 保存热点可见性的数据
      * @return
@@ -1031,6 +1026,11 @@ public class SceneEditController extends BaseController {
         return sceneEditService.saveTour(param);
     }
 
+    @PostMapping(value = "/downloadTourVideo")
+    public void tranferRoam(@RequestParam("file") MultipartFile file) throws Exception {
+        sceneUploadService.formatMp4(file, this.response);
+    }
+
     /**
      * 删除导览
      * @param param

+ 13 - 14
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneUploadServiceImpl.java

@@ -234,30 +234,29 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
     @Override
     public void formatMp4(MultipartFile file, HttpServletResponse response) throws Exception {
 
-        String extName = cn.hutool.core.io.FileUtil.extName(file.getOriginalFilename());
-        File oldFile = File.createTempFile(UUID.randomUUID().toString() ,extName);
+        String fileName = file.getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf("."));
+        File oldFile = File.createTempFile(UUID.randomUUID().toString() ,suffix);
         file.transferTo(oldFile);
 
-//        File destFile = File.createTempFile(UUID.randomUUID().toString() ,extName);
-        String descFilePath = ConstantFilePath.SCENE_V4_PATH + "abcd/" + file.getOriginalFilename();
-        File file1 = new File(descFilePath);
-        if(!file1.getParentFile().exists()){
-            file1.mkdir();
-        }
-        CreateObjUtil.formatMp4(oldFile.getPath(), descFilePath);
-
-        if(!cn.hutool.core.io.FileUtil.exist(descFilePath)){
+        File destFile = File.createTempFile(UUID.randomUUID().toString() ,suffix);
+//        File file1 = new File(descFilePath);
+//        if(!file1.getParentFile().exists()){
+//            file1.mkdir();
+//        }
+        CreateObjUtil.formatMp4(oldFile.getPath(), destFile.getPath());
+//
+        if(!cn.hutool.core.io.FileUtil.exist(destFile.getPath())){
             throw new BusinessException(ErrorCode.FAILURE_CODE_5038);
         }
-
-        File outFile = new File(descFilePath);
+        File outFile = new File(destFile.getPath());
         //定义处理流
         try(
             FileInputStream inputStream = new FileInputStream(outFile);
             OutputStream outputStream = response.getOutputStream()
         ){
             byte[] cache = new byte[1024];
-            response.setHeader(HttpHeaders.CONTENT_TYPE, "video/mp4");
+            response.setHeader(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
             response.setHeader(HttpHeaders.CONTENT_LENGTH, inputStream.available()+"");
             response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(file.getOriginalFilename(), "UTF-8"));
             int flag;