腾讯云 云点播 JAVASDK上传
maven
<dependency> <groupId>com.qcloud</groupId> <artifactId>vod_api</artifactId> <version>2.1.5</version> //如果项目无slf4j-log4j12和cos_api不需要增加此代码 <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>com.qcloud</groupId> <artifactId>cos_api</artifactId> </exclusion> </exclusions> </dependency>
服务器上传
public static String uploadFile(MultipartFile multipartFile) { try { //生成文件名 String fileName = UUID.randomUUID().toString() + StrPool.DOT + FilenameUtils.getExtension(multipartFile.getOriginalFilename()); String tenant = BaseContextHandler.getTenant(); //日期文件夹 String relativePath = Paths.get(tenant, LocalDate.now().format(DateTimeFormatter.ofPattern(DEFAULT_MONTH_FORMAT_SLASH))).toString(); // web服务器存放的绝对路径 String absolutePath = Paths.get("/data/projects/uploadfile/file/", relativePath).toString(); java.io.File outFile = new java.io.File(Paths.get(absolutePath, fileName).toString()); org.apache.commons.io.FileUtils.writeByteArrayToFile(outFile, multipartFile.getBytes()); String url = new StringBuilder("") .append(absolutePath) .append(StrPool.SLASH) .append(fileName) .toString(); //替换掉windows环境的路径 url = StrUtil.replace(url, "\\", StrPool.SLASH); url = StrUtil.replace(url, "\", StrPool.SLASH); //url用来获取上传文件的本地位置 return url; } catch (CosClientException e){ e.printStackTrace(); throw new BizException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new BizException(e.getMessage()); } }
简单上传 https://cloud.tencent.com/document/product/266/10276
//url为本地文件URL地址 public static VodUploadResponse simpleUpload(String url) { // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密 // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取 VodUploadClient client = new VodUploadClient("secretId", "secretKey"); VodUploadRequest request = new VodUploadRequest(); //任务流名称 如果不走任务流会播放器会出现 1005错误 request.setProcedure("LongVideoPreset"); //本地视频地址 request.setMediaFilePath("C:\Users\Administrator\Videos\金舟录屏大师\jzrecord_2020-08-28-17-34-54.mp4"); try { VodUploadResponse response = client.upload("ap-guangzhou", request); System.out.println("Upload FileId = {"+response.getFileId()+"}"); return response; } catch (Exception e) { // 业务方进行异常处理 System.out.println("Upload Err = {"+e+"}"); throw new BizException(e.getMessage()); } }