|
|
|
@@ -99,7 +99,7 @@ public class AliyunVedioUpload { |
|
|
|
// 任何上传方式文件名必须包含扩展名 |
|
|
|
String fileName = "/Users/test/video/test.mp4"; |
|
|
|
// 本地文件上传 |
|
|
|
uploadVideo(accessKeyId, accessKeySecret, title, fileName); |
|
|
|
uploadVideo(accessKeyId, accessKeySecret,"cn-beijing", title, fileName); |
|
|
|
|
|
|
|
// 待上传视频的网络流地址 |
|
|
|
String url = "http://test.aliyun.com/video/test.mp4"; |
|
|
|
@@ -107,7 +107,7 @@ public class AliyunVedioUpload { |
|
|
|
// 2.网络流上传 |
|
|
|
// 文件扩展名,当url中不包含扩展名时,需要设置该参数 |
|
|
|
String fileExtension = "mp4"; |
|
|
|
uploadURLStream(accessKeyId, accessKeySecret, title, url, fileExtension); |
|
|
|
uploadURLStream(accessKeyId, accessKeySecret, "cn-beijing",title, url, fileExtension); |
|
|
|
|
|
|
|
// 3.文件流上传 |
|
|
|
// testUploadFileStream(accessKeyId, accessKeySecret, title, fileName); |
|
|
|
@@ -126,7 +126,7 @@ public class AliyunVedioUpload { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
uploadStream(accessKeyId, accessKeySecret, title, fileName, inputStream); |
|
|
|
uploadStream(accessKeyId, accessKeySecret, "cn-beijing",title, fileName, inputStream); |
|
|
|
|
|
|
|
// 二、图片上传 |
|
|
|
|
|
|
|
@@ -139,9 +139,9 @@ public class AliyunVedioUpload { |
|
|
|
// 三、m3u8文件上传 |
|
|
|
|
|
|
|
// 1.上传本地m3u8音视频文件 |
|
|
|
uploadLocalM3u8(accessKeyId, accessKeySecret); |
|
|
|
uploadLocalM3u8(accessKeyId, accessKeySecret,"cn-beijing"); |
|
|
|
// 2.上传网络m3u8音视频文件 |
|
|
|
uploadWebM3u8(accessKeyId, accessKeySecret); |
|
|
|
uploadWebM3u8(accessKeyId, accessKeySecret,"cn-beijing"); |
|
|
|
// 四、辅助媒资上传 |
|
|
|
// 辅助媒资-本地文件上传 |
|
|
|
// testUploadAttachedMediaLocalFile(accessKeyId, accessKeySecret); |
|
|
|
@@ -157,7 +157,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param title |
|
|
|
* @param fileName |
|
|
|
*/ |
|
|
|
public static UploadVideoResponse uploadVideo(String accessKeyId, String accessKeySecret, String title, String fileName) { |
|
|
|
public static UploadVideoResponse uploadVideo(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName) { |
|
|
|
UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName); |
|
|
|
/* 可指定分片上传时每个分片的大小,默认为2M字节 */ |
|
|
|
request.setPartSize(2 * 1024 * 1024L); |
|
|
|
@@ -197,9 +197,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadVideoImpl uploader = new UploadVideoImpl(); |
|
|
|
UploadVideoResponse response = uploader.uploadVideo(request); |
|
|
|
return response; |
|
|
|
@@ -215,7 +215,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param fileName |
|
|
|
* @param url |
|
|
|
*/ |
|
|
|
public static UploadURLStreamResponse uploadURLStream(String accessKeyId, String accessKeySecret, String title, String url, String fileExtension) { |
|
|
|
public static UploadURLStreamResponse uploadURLStream(String accessKeyId, String accessKeySecret,String regionId, String title, String url, String fileExtension) { |
|
|
|
UploadURLStreamRequest request = new UploadURLStreamRequest(accessKeyId, accessKeySecret, title, url); |
|
|
|
|
|
|
|
/* 文件扩展名*/ |
|
|
|
@@ -251,9 +251,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadVideoImpl uploader = new UploadVideoImpl(); |
|
|
|
UploadURLStreamResponse response = uploader.uploadURLStream(request); |
|
|
|
return response; |
|
|
|
@@ -267,7 +267,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param title |
|
|
|
* @param fileName |
|
|
|
*/ |
|
|
|
private static void uploadFileStream(String accessKeyId, String accessKeySecret, String title, String fileName) { |
|
|
|
private static void uploadFileStream(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName) { |
|
|
|
UploadFileStreamRequest request = new UploadFileStreamRequest(accessKeyId, accessKeySecret, title, fileName); |
|
|
|
/* 是否使用默认水印(可选),指定模板组ID时,根据模板组配置确定是否使用默认水印*/ |
|
|
|
//request.setShowWaterMark(true); |
|
|
|
@@ -294,9 +294,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadVideoImpl uploader = new UploadVideoImpl(); |
|
|
|
UploadFileStreamResponse response = uploader.uploadFileStream(request); |
|
|
|
System.out.print("RequestId=" + response.getRequestId() + "\n"); //请求视频点播服务的请求ID |
|
|
|
@@ -319,7 +319,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param fileName |
|
|
|
* @param inputStream |
|
|
|
*/ |
|
|
|
public static UploadStreamResponse uploadStream(String accessKeyId, String accessKeySecret, String title, String fileName, InputStream inputStream) { |
|
|
|
public static UploadStreamResponse uploadStream(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName, InputStream inputStream) { |
|
|
|
UploadStreamRequest request = new UploadStreamRequest(accessKeyId, accessKeySecret, title, fileName, inputStream); |
|
|
|
/* 是否使用默认水印(可选),指定模板组ID时,根据模板组配置确定是否使用默认水印*/ |
|
|
|
//request.setShowWaterMark(true); |
|
|
|
@@ -346,9 +346,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadVideoImpl uploader = new UploadVideoImpl(); |
|
|
|
UploadStreamResponse response = uploader.uploadStream(request); |
|
|
|
return response; |
|
|
|
@@ -361,7 +361,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param accessKeyId |
|
|
|
* @param accessKeySecret |
|
|
|
*/ |
|
|
|
public static void uploadImageLocalFile(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadImageLocalFile(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
/* 图片类型(必选)取值范围:default(默认),cover(封面),watermark(水印)*/ |
|
|
|
String imageType = "cover"; |
|
|
|
UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType); |
|
|
|
@@ -384,7 +384,7 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
UploadImageImpl uploadImage = new UploadImageImpl(); |
|
|
|
UploadImageResponse response = uploadImage.upload(request); |
|
|
|
System.out.print("RequestId=" + response.getRequestId() + "\n"); |
|
|
|
@@ -405,7 +405,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param accessKeyId |
|
|
|
* @param accessKeySecret |
|
|
|
*/ |
|
|
|
public static void uploadImageStream(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadImageStream(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
/* 图片类型(必选)取值范围:default(默认),cover(封面),watermark(水印)*/ |
|
|
|
String imageType = "cover"; |
|
|
|
UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType); |
|
|
|
@@ -458,7 +458,7 @@ public class AliyunVedioUpload { |
|
|
|
* m3u8Filename: 本地m3u8索引文件的绝对路径,且m3u8文件的分片信息必须是相对路径,不能含有URL或本地绝对路径 |
|
|
|
* sliceFilenames: ts分片文件的绝对路径列表,如指定则以此为准,若不指定,则自动解析 m3u8Filename 里的m3u8文件 |
|
|
|
*/ |
|
|
|
public static void uploadLocalM3u8(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadLocalM3u8(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
String title = "test_upload_local_m3u8"; |
|
|
|
String m3u8Filename = "/Users/test/0e9ecfc6da934d1887ed7bdfc925ecf5/cc38da35c7b24de0abe58619cdd7a8-6479a12446b994719838e0307f6458-ld.m3u8"; |
|
|
|
UploadLocalM3u8Request request = new UploadLocalM3u8Request(accessKeyId, accessKeySecret, title, m3u8Filename); |
|
|
|
@@ -496,9 +496,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
// request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
// request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadM3u8FileImpl uploadM3u8File = new UploadM3u8FileImpl(); |
|
|
|
UploadLocalM3u8Response uploadLocalM3u8Response = uploadM3u8File.uploadLocalM3u8(request); |
|
|
|
System.out.println("code = " + uploadLocalM3u8Response.getCode()); |
|
|
|
@@ -514,7 +514,7 @@ public class AliyunVedioUpload { |
|
|
|
* m3u8FileURL: 网络m3u8索引文件的URL地址,且m3u8文件的分片信息必须是相对地址,不能含有URL或本地绝对路径 |
|
|
|
* sliceFileURLs: ts分片文件的URL地址列表;需自行拼接ts分片的URL地址列表 |
|
|
|
*/ |
|
|
|
public static void uploadWebM3u8(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadWebM3u8(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
String title = "test_upload_web_m3u8"; |
|
|
|
String m3u8FileURL = "http://test.aliyun.com/f0d644abc547129e957b386f772c72/a0e1e2817ab9425aa558fe67a90e717f-538087dcf2c201c31ce4324bf76af691-ld.m3u8"; |
|
|
|
UploadWebM3u8Request request = new UploadWebM3u8Request(accessKeyId, accessKeySecret, title, m3u8FileURL); |
|
|
|
@@ -554,9 +554,9 @@ public class AliyunVedioUpload { |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
//request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* ECS部署区域*/ |
|
|
|
// request.setEcsRegionId("cn-shanghai"); |
|
|
|
request.setEcsRegionId(regionId); |
|
|
|
UploadM3u8FileImpl uploadM3u8File = new UploadM3u8FileImpl(); |
|
|
|
UploadWebM3u8Response uploadWebM3u8Response = uploadM3u8File.uploadWebM3u8(request); |
|
|
|
System.out.println("code = " + uploadWebM3u8Response.getCode()); |
|
|
|
@@ -572,7 +572,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param accessKeyId |
|
|
|
* @param accessKeySecret |
|
|
|
*/ |
|
|
|
public static void uploadAttachedMediaLocalFile(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadAttachedMediaLocalFile(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
/* 业务类型 */ |
|
|
|
String businessType = "watermark"; |
|
|
|
/* 文件扩展名 */ |
|
|
|
@@ -591,7 +591,7 @@ public class AliyunVedioUpload { |
|
|
|
/* 存储区域(可选) */ |
|
|
|
request.setStorageLocation("out-20170323225118266-5l3hs5gqwa.oss-cn-shanghai.aliyuncs.com"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* 设置应用ID*/ |
|
|
|
//request.setAppId("app-1000000"); |
|
|
|
UploadAttachedMediaImpl uploader = new UploadAttachedMediaImpl(); |
|
|
|
@@ -615,7 +615,7 @@ public class AliyunVedioUpload { |
|
|
|
* @param accessKeyId |
|
|
|
* @param accessKeySecret |
|
|
|
*/ |
|
|
|
public static void uploadAttachedMediaStream(String accessKeyId, String accessKeySecret) { |
|
|
|
public static void uploadAttachedMediaStream(String accessKeyId, String accessKeySecret,String regionId) { |
|
|
|
/* 业务类型 */ |
|
|
|
String businessType = "watermark"; |
|
|
|
/* 文件扩展名 */ |
|
|
|
@@ -644,7 +644,7 @@ public class AliyunVedioUpload { |
|
|
|
/* 存储区域(可选) */ |
|
|
|
request.setStorageLocation("out-20170323225118266-5l3****wa.oss-cn-shanghai.aliyuncs.com"); |
|
|
|
/* 点播服务接入点 */ |
|
|
|
request.setApiRegionId("cn-shanghai"); |
|
|
|
request.setApiRegionId(regionId); |
|
|
|
/* 设置应用ID*/ |
|
|
|
// request.setAppId("app-1000000"); |
|
|
|
// 开始上传 |
|
|
|
|