当前位置:网站首页>Tencent Cloud VOD uploads video files to solve the path problem

Tencent Cloud VOD uploads video files to solve the path problem

2022-08-06 07:54:23Youmans_station

Tencent Cloud VOD needs,视频的路径.
思路一,MultipartFileGet the file path from the cache-失败
思路二,Store the horseshoe pat file stream locally,Then set the local path up.
废话少说,直接上代码.

    //上传视频
    @Override
    public String uploadVideo(MultipartFile file) {
    
        try {
    
            VodUploadClient client =
                    new VodUploadClient(ConstantPropertiesUtil.ACCESS_KEY_ID,
                                        ConstantPropertiesUtil.ACCESS_KEY_SECRET);
            VodUploadRequest request = new VodUploadRequest();

// String fileName = UUID.randomUUID() + "." + originalFilename.split("\\.")[originalFilename.split("\\.").length - 1];
            //Get the compiled file location
// File f = new File(this.getClass().getResource("/").getPath());
// String str = f.getPath() ;387702304156452066
// System.err.println(str);
// String bb= str.substring(0,str.lastIndexOf("target")) ;
            //copyFile(inputStream,bb);
            String fileName = file.getOriginalFilename();
            fileName = UUID.randomUUID() + "." + fileName.split("\\.")[fileName.split("\\.").length - 1];

// Get local video location
            this.tempVideoPath = File.listRoots()[1].getPath()+File.separator+"data"+File.separator;
            File ff=new File(this.tempVideoPath);
            if(!ff.exists()){
    
                ff.mkdirs() ;
            }

            file.transferTo(new File(this.tempVideoPath + fileName));

            String   filePath = this.tempVideoPath+fileName;
            System.out.println(this.tempVideoPath+fileName);

            //视频本地地址
            request.setMediaFilePath(filePath);
            //指定任务流
            request.setProcedure("LongVideoPreset");



            //调用上传方法,传入接入点地域及上传请求.
            VodUploadResponse response = client.upload("ap-guangzhou", request);
            //返回文件id保存到业务表,用于控制视频播放
            String fileId = response.getFileId();
            System.out.println("Upload FileId = {}"+response.getFileId());

            new File(filePath).delete();
            return fileId;
        } catch (Exception e) {
    
            System.out.println(e.toString());
        }
        return null;
    }
原网站

版权声明
本文为[Youmans_station]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/218/202208060744392742.html

随机推荐