uploadService
1. Upload Local Video
Description
1、快捷上传多种格式的媒体文件。
2、支持上传时的各种设置,如文件标题、描述、标签、上传目录、是否开启课件优化处理等。
3、采用分片并发上传的方式,支持断点续传,续传请查看当前文档下一个方法。
4、PolyvUploadClient.uploadVideo()方法三个参数分别为 分片上传本地视频请求实体、上传回调、是否打印日志
接口地址(仅做说明使用):https://api.polyv.net/
Call Constraints
- API calls are rate-limited. Click for details. For common call exceptions, click here.
Unit Test
@Test
public void testUploadVideoPart() {
VodUploadVideoRequest vodUploadVideoRequest = new VodUploadVideoRequest();
Boolean vodUploadVideoResponse;
String videoFile = getClass().getResource("/file/polyv.mp4").getPath();
//构建视频上传客户端,可传入分片大小(默认为1MB,大小限定为100KB~5GB),分片文件夹路径(默认为checkpoint_location),上传线程数(默认为5个),此对象全局唯一
PolyvUploadClient client = new PolyvUploadClient(1024 * 1024, "checkpoint_location", 5);
vodUploadVideoRequest.setFile(new File(videoFile))
.setTitle("保利威宣传视频")
.setDescribe("保利威是全球领先的企业直播服务商,隶属于广州易方信息科技股份有限公司,致力于通过可集成、可定制的视频直播技术,为企业搭建自主私域直播系统,并提供直播全流程运营与现场执行服务。")
.setTag("宣传视频")
//.setCategoryId("1622165542751")
.setScreenCap(0)
.setKeepSource(0)
.setState("junitTest")
.setWatermarkLocation("1")
.setWatermark("https://water/1/146b754735/water_146b7547351767584889357_1.png");
vodUploadVideoResponse = client.buildOSSService(vodUploadVideoRequest).upload(new UploadCallBack() {
@Override
public void start(String videoPoolId) {
log.debug("开始分片上传视频,videoId:{}", videoPoolId);
}
@Override
public void process(String videoPoolId, long hasUploadBytes, long totalFileBytes) {
log.debug("分片上传成功,videoId:{},已上传分片大小:{},总视频大小{}", videoPoolId, hasUploadBytes, totalFileBytes);
}
@Override
public void complete(String videoPoolId) {
log.debug("所有分片上传成功,videoId:{}", videoPoolId);
}
@Override
public void success(String videoPoolId) {
log.debug("所有分片上传成功并处理完成,请等待后台审核,videoId:{}", videoPoolId);
}
@Override
public void error(String videoPoolId, UploadErrorMsg errorMsg) {
log.error("上传视频失败,videoId:{},错误信息:{}", videoPoolId, errorMsg);
}
}, false);
}
Unit Test Notes
- On a successful request, a Boolean object is returned. The B-end processes business logic based on this object.
- If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ]. - If the server encounters an exception, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| title | false | String | Video title. Defaults to the file name with extension, e.g., test.mp4 |
| describe | false | String | Video description. Default is empty. |
| tag | false | String | Video tags, separated by commas. Default is empty. |
| categoryId | false | String | Video category. Default is "Default Category". |
| screenCap | false | Integer | Screen recording optimization. When set to 1, the uploaded video will not use the default compression encoding, and the video dimensions will not be compressed, ensuring video clarity. Default value is 0. |
| keepSource | false | Integer | Source file playback. 1 to enable, 0 to disable. When enabled, the video is not transcoded (only valid for newly uploaded videos). Default value is 0: non-source file playback. |
| file | true | File | The video file to upload. |
| state | false | String | If this field is submitted, it will be transparently returned in the upload completion event callback. |
| watermark | false | string | Custom watermark image URL. The image format must be PNG. Supports http and https. |
| watermarkLocation | false | string | Custom watermark image position. If this parameter is absent, the watermark display follows the category and account settings. 1: Top left; 2: Top right; 3: Bottom left; 4: Bottom right. |
Return Object Description
Returns true on successful upload, false on failure. The error callback returns the video ID. You can use the "Resumable Upload Local Video" feature to resume the upload.
2. Resumable Upload Local Video
Description
断点续传未上传成功的本地视频文件
PolyvUploadClient.uploadVideo()方法三个参数分别为 分片上传本地视频请求实体、上传回调、是否打印日志
接口地址(仅做说明使用):https://api.polyv.net/
Call Constraints
- API calls are rate-limited. Click for details. For common call exceptions, click here.
Unit Test
@Test
public void testUploadVideoPartSequel() {
VodUploadVideoPartsRequest vodUploadVideoPartsRequest = new VodUploadVideoPartsRequest();
Boolean vodUploadVideoResponse;
String videoFile = getClass().getResource("/file/polyv.mp4").getPath();
String videoId = "ac59aff03d153b3ed5d7f64194279af9_a";
vodUploadVideoPartsRequest.setFile(new File(videoFile)).setVideoId(videoId);
try {
PolyvUploadClient client = new PolyvUploadClient(1024 * 1024, "checkpoint_location", 5);
vodUploadVideoResponse = client.buildOSSService(vodUploadVideoPartsRequest).upload(new UploadCallBack() {
@Override
public void start(String videoPoolId) {
log.debug("开始分片上传视频,videoId:{}", videoPoolId);
}
@Override
public void process(String videoPoolId, long hasUploadBytes, long totalFileBytes) {
log.debug("分片上传成功,videoId:{},已上传分片大小:{},总视频大小{}", videoPoolId, hasUploadBytes, totalFileBytes);
}
@Override
public void complete(String videoPoolId) {
log.debug("所有分片上传成功,videoId:{}", videoPoolId);
}
@Override
public void success(String videoPoolId) {
log.debug("所有分片上传成功并处理完成,请等待后台审核,videoId:{}", videoPoolId);
}
@Override
public void error(String videoPoolId, UploadErrorMsg errorMsg) {
log.error("上传视频失败,videoId:{},错误信息:{}", videoPoolId, errorMsg);
}
}, false);
log.debug("测试续传视频返回状态:{}", vodUploadVideoResponse);
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Notes
- On a successful request, a Boolean object is returned. The B-end processes business logic based on this object.
- If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ]. - If the server encounters an exception, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| file | true | File | The video file to upload. |
| videoId | true | String | The video ID for resuming the upload. |
| state | false | String | If this field is submitted, it will be transparently returned in the upload completion event callback. |
Return Object Description
Returns the video ID on successful upload. The error callback also returns the video ID.
3. Upload Remote Video
Description
上传远程视频(异步上传),具体上传情况可调用“分页查询视频同步列表”查看
接口地址(仅做说明使用):https://api.polyv.net/v2/video/grab/%s/upload/multi
Call Constraints
API calls are rate-limited. Click for details. For common call exceptions, click here.
The watermark link must be in PNG format.
Either
uploadInfosor (fileUrl,title) must be provided.uploadInfoshas higher priority than (fileUrl,title). UsinguploadInfosis recommended.
Unit Test
@Test
public void testUploadHttpVideoList() throws IOException, NoSuchAlgorithmException {
VodUploadHttpVideoListRequest vodUploadHttpVideoListRequest = new VodUploadHttpVideoListRequest();
Boolean vodUploadHttpVideoListResponse = null;
try {
VodUploadHttpVideoListRequest.UploadInfos uploadInfo = new VodUploadHttpVideoListRequest.UploadInfos();
List<VodUploadHttpVideoListRequest.UploadInfos> uploadInfos = new ArrayList<>(Arrays.asList(uploadInfo));
uploadInfo.setFileUrl("http://sadboytest.oss-cn-shenzhen.aliyuncs.com/test.mp4")
.setTitle("junit-远程批量上传视频")
.setState("state");
vodUploadHttpVideoListRequest.setCategoryId("1622165542751")
.setScreenCap(0)
.setWatermark("http://sadboytest.oss-cn-shenzhen.aliyuncs.com/a.png")
.setWatermarkLocation("1")
.setUploadInfos(uploadInfos);
vodUploadHttpVideoListResponse = new VodUploadServiceImpl().uploadHttpVideoList(
vodUploadHttpVideoListRequest);
Assert.assertTrue(vodUploadHttpVideoListResponse);
if (vodUploadHttpVideoListResponse) {
//to do something ......
log.debug("测试上传远程视频成功");
}
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Notes
- On a successful request, a Boolean object is returned. The B-end processes business logic based on this object.
- If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ]. - If the server encounters an exception, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| categoryId | false | String | Sets the category for the uploaded video. When categoryId is 1, it indicates the root directory of the user's upload space. [Corresponds to the cataid field in the API documentation] |
| screenCap | false | Integer | Screen recording optimization. When set to 1, the uploaded video will not use the default compression encoding, and the video dimensions will not be compressed, ensuring video clarity. Default value is 0. [Corresponds to the luping field in the API documentation] |
| watermark | false | String | Custom watermark image URL. The image format must be PNG. Supports http and https. |
| watermarkLocation | false | String | Custom watermark image position. If this parameter is absent, the watermark display follows the category or account settings. 1: Top left; 2: Top right; 3: Bottom left; 4: Bottom right. |
| uploadInfos | false | Array | JSON array of video upload information, up to 100 items. See UploadInfos Parameter Description |
UploadInfos Parameter Description
| Parameter Name | Type | Description |
|---|---|---|
| fileUrl | String | URL of the video to upload. Supports http and https protocols. Length limit: 1000 characters. |
| title | String | Video title. Length limit: 100 characters. |
| state | String | Custom data. Length limit: 100 characters. If this field is submitted, it will be transparently returned in the upload completion callback. |
Return Object Description
Returns true if the asynchronous upload submission is successful, false if it fails. The actual upload success is determined by the callback.
4. Upload Video Cover Image
Description
通过图片文件或http链接上传视频或多个分类的预览图
接口地址(仅做说明使用):https://api.polyv.net/v2/video/upload-cover-image
Call Constraints
API calls are rate-limited. Click for details. For common call exceptions, click here.
If the
videoIdsparameter is provided, it takes precedence. IfvideoIdsis not provided,categoryIdsis used. Both parameters cannot be empty simultaneously.For image upload, choose any one of the three forms. If multiple are provided, the first non-empty form is selected in the order:
imageFile,imageUrl,imageBase64.Only png, jpg, jpeg, gif, and bmp image formats are supported. The image size must not exceed 5MB.
Unit Test
@Test
public void testUploadVideoCoverImage() throws IOException, NoSuchAlgorithmException {
VodUploadVideoCoverImageRequest vodUploadVideoCoverImageRequest = new VodUploadVideoCoverImageRequest();
VodUploadVideoCoverImageResponse vodUploadVideoCoverImageResponse = null;
try {
String path = getClass().getResource("/img/cover.jpg").getPath();
vodUploadVideoCoverImageRequest.setVideoIds(
"1b448be32345b255cabc3fe8d65a4d00_1,1b448be3234406608b7838c7ef6b597c_1")
.setCategoryIds("1615286323771,1615536384688")
.setImageFile(new File(path));
vodUploadVideoCoverImageResponse = new VodUploadServiceImpl().uploadVideoCoverImage(
vodUploadVideoCoverImageRequest);
Assert.assertTrue(vodUploadVideoCoverImageResponse != null);
if (vodUploadVideoCoverImageResponse != null) {
log.debug("测试上传视频封面图成功{}", JSON.toJSONString(vodUploadVideoCoverImageResponse));
}
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Notes
- On a successful request, a
VodUploadVideoCoverImageResponseobject is returned. The B-end processes business logic based on this object. - If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ]. - If the server encounters an exception, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| videoIds | false | String | Video IDs, separated by commas, e.g., e2e85038_e,e2e85039_e. [Corresponds to the vids field in the API documentation] |
| categoryIds | false | String | Category IDs, separated by commas. [Corresponds to the cateIds field in the API documentation] |
| imageFile | false | File | Image file. |
| imageUrl | false | String | Image HTTP URL. |
| imageBase64 | false | String | Base64 encoded string of the image file. |
Return Object Description
| Parameter Name | Type | Description |
|---|---|---|
| imageUrlSmall | String | Small image URL. |
| imageUrlBig | String | Large image URL. |
5. Upload Video Watermark
Description
上传某一级分类或用户级别的视频水印,设置成功后对新上传的视频生效
水印图片需要为png格式,图片宽或高的尺寸超过256px时会被等比缩放
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/watermarkSetting
Call Constraints
- API calls are rate-limited. Click for details. For common call exceptions, click here.
Unit Test
@Test
public void testUploadWatermark() throws IOException, NoSuchAlgorithmException {
VodUploadWatermarkRequest vodUploadWatermarkRequest = new VodUploadWatermarkRequest();
Boolean vodUploadWatermarkResponse = null;
try {
String path = getClass().getResource("/img/water.png").getPath();
vodUploadWatermarkRequest.setImage(new File(path)).setCategoryId("1602300731843");
vodUploadWatermarkResponse = new VodUploadServiceImpl().uploadWatermark(vodUploadWatermarkRequest);
Assert.assertTrue(vodUploadWatermarkResponse);
if (vodUploadWatermarkResponse) {
//to do something ......
log.debug("测试上传视频水印成功");
}
} catch (PloyvSdkException e) {
//参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
log.error(e.getMessage(), e);
// 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
throw e;
} catch (Exception e) {
log.error("SDK调用异常", e);
throw e;
}
}
Unit Test Notes
- On a successful request, a Boolean object is returned. The B-end processes business logic based on this object.
- If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ]. - If the server encounters an exception, a
PloyvSdkExceptionis thrown. The error message can be found inPloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request, request ID: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]
Request Parameter Description
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| image | true | File | The watermark image to upload. |
| categoryId | false | String | Category ID. Only first-level categories can have watermarks set. If not provided, the user-level watermark is set. [Corresponds to the cataid field in the API documentation] |
| watermarkLocation | false | String | Watermark display position: 1: Top left; 2: Top right; 3: Bottom left; 4: Bottom right; 0: Do not display watermark. |
Return Object Description
true: Upload successful; false: Upload failed.
