开发者学堂课程【微服务+全栈在线教育实战项目演练(SpringCloud Alibaba+SpringBoot):技术点-阿里云视频点播(上传视频)】学习笔记,与课程紧密连接,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/667/detail/11403
技术点-阿里云视频点播(上传视频)
目录:
一、本地文件上传接口
二、URL 网络流上传
三、流式上传接口
四、本地上传
一、本地文件上传接口
@param accessKeyId
@param accessKeySecret
@param title
@param fileName
private static void testUploadvideo (String accessKeyId,stringaccessKeySecret.String.title.string.
fileName
UploadVideoRequest request = new UploadvideoRequest(accessKeyId,accessKeySecret,title,fileName)
UploadVideoImpl uploader = new UppadVideoImpl();
UploadVideoResponse response = uploader.uploadVideo(request);
system.out.print("RequestId="+response.getRequestId()+"\n");//请求视频点播服务的请求ID
if (response.issuccess())
System.out.print("VideoId="+response.getVideoId()+"\n");
else
//如果设置回调 URL 无效,不影响视频上传,可以返回 VideoId 同时会返回错误码\其他情况上传失败时,
VicSystem.out.print("VideoId=" + response.getVideoId()+"\n");
System.out.print("Errorcode=" + response.getcode()+"\n");
System.out.print("ErrorMessage=" + response.getMessage()+"\n");
二、URL 网络流上传
介绍:支持断点续传,最大支持48.8TB 的单个文件。
该上传方式需要先将网络文件下载到本地磁盘,再进行上传,所以要保证本地磁盘有充足的空间。
当您设置的 URL 中不包括文件扩展名时,需要单独设置
fileExtension,表示文件扩展名。
@param accessKeyId
@param accessReysecret
@param title
@param fileName
@param urI
private static.void testUploadURLstream (string accessKeyId, String accessKeySecret, string.title.stringUploadURLStreamRequest request = new UploadURLStreamRequest (accessKeyId,accessKeysecret, title,url)
三、流式上传接口
@param accessKeyId
@param accessKeySecret
@param title
@peram fileMame
@param inputstream
private.static.void.testUploadstream(string,accessKeyId,string.accessKeysecret,string title,string.filenam.UploadstreamRequest request =new UploadstreamRequest(accessKeyId,aceessKeySecret, title, fileName ,
四、本地上传
request.setEnableCheckpoint(false);
UploadVideoImpl uploader = new UploadVideoImpl ();
UploadVideoResponse response = uploader.uploadVideo(request);
System.out.print("RequestId="+response.getRequestId()+"\n");//请求视频点播服务的请求ID
if (response.isSuccess()) {
System.out.print("VLdeoId="+response.getVideoId()+"\n");
else{
/*如果设置回调 URL 无效,不影响视频上传,可以返回 VIdeoId 同时会返回错误码。
其他情况上传失败时,VideoId 为空,此时需要根据返回错误码分析具体错误原因*/
System.out.print("VideoId="+ response.getvideoId()+"\n");
System.out.print("ErrorCode="+ response.getCode()+"\n");
System.out.print("ErrorMessage-"+response.getMessage()+"\n");
if(response.isSuccess0)
System.out.print("VideoId="+response.getVideoIdO+"\n");
else
public static void main(String[] args){
String accessKeyId="LTAI4FvvVEWiTJ3GNJJqJnk7" ;
String accessKeySecret="9st82dv7EvFk9mTjY01XXbM632fRbG" ;
Stringtitle”6-What If I Want to Move Faste-upload by sdk";//上传之后文件名称
String fileName ="P:/6- What If I Want to Move Faster.mp4";//本地文件路径和名称
//上传视频的方法
UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret,title,fileName);/*可指定分片上传时每个分片的大小,默认为2M 字节*/
request setPartSize(2 * 1024 * 1024);
/*可指定分片_上传时的并发线程数,默认为1,(注:该配置会占用服务器CPU资源,需根据服务器情况指定)*/
request.setTaskNum(1);
UploadVideoImpl uploader = new UploadVideoImpl();
UploadVideoResponse response = uploader. uploadVideo (request);
System.out print("RequestId="+response.getRequestId()+"\n");//请求视频点播服务的请求 ID
public static void main(String[] args) throws Exception (
//1根据视频iD获取视频播放凭证DefaultAcsClient client=Init0bject.initVodClient(accessKeyId: LTAI4FvvVEWiTJ3GNJJqJnk7'
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest 0;GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse0;
request.setVideoId('474be24d43ad4f76af344b9f4daaabd1");
response = client.getAcsResponse(request);
System.out.println('playAuth:"tresponse. getPlayAuth0) ;
注:四个参数
(1)StringaccessKeyId
="LTAI4FvvVEWiTJ3GNJJqJnk7";
(2)String accessKeySecret
="9st82dv7EvFk9mT jY01XXbM632fRbd";
(3)String title
="6-what If I Want to Move Faster-upload by sdk";(上传之后文件名称)
(4)String fileName
="F:/6-What If I Want to Move Faster.mp4”; (本地文件路径和名称)
例如:
"E: /共享/资源/课程视频/3 - Haw Does Project Submission wonk.mp4"";
注:
当运行结果显示
VideoId=0e6daf0bdc9a43d7a277eb0481cf609b即上传成功