腾讯云点播需要,视频的路径。
思路一,MultipartFile从缓存中取文件路径-失败
思路二,将马蹄帕特文件流存储到本地,再将本地路径设置上去。
废话少说,直接上代码。
//上传视频
@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];
//获取编译后文件位置
// 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];
// 获取本地视频位置
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;
}