fileService
1. Upload Document to a Lesson
Description
上传课节文档接口
接口地址(仅做说明使用):https://api.polyv.net/hi-class-api/open/file/v1/upload-doc
Call Constraints
API calls are rate-limited. Click here for details. For common call exceptions, click here.
The uploaded file must not exceed 50MB. Supported formats: (ppt, pdf, pptx, doc, docx, wps, xls, xlsx).
Only one of
fileorurlneeds to be provided. If both are provided, thefilefield takes precedence.
Unit Test
@Test
public void testUploadDoc() throws IOException, NoSuchAlgorithmException {
VClassUploadDocRequest vClassUploadDocRequest;
VClassUploadDocResponse vClassUploadDocResponse;
try {
String path = VClassFileServiceTest.class.getResource("/file/PPT.pptx").getPath();
Long lessonId = super.createLesson();
vClassUploadDocRequest = VClassUploadDocRequest.builder()
.lessonId(lessonId)
// .file(new File(path))
.url("https://help.polyv.net/third_res/PPT.pptx")
.docName("测试上传文档")
.callbackUrl("http://www.baidu.com/callback")
.build();
vClassUploadDocResponse = new VClassFileServiceImpl().uploadDoc(vClassUploadDocRequest);
Assert.assertNotNull(vClassUploadDocResponse);
if (vClassUploadDocResponse != null) {
//to do something ......
log.debug("测试上传文档到某个课节成功 {}", JSON.toJSONString(vClassUploadDocResponse));
//TODO 此处创建完成后删除了文档,正式使用需删除该语句
super.deleteDoc(lessonId, vClassUploadDocResponse.getFileId());
}
} 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 Description
On a successful request, a
VClassUploadDocResponseobject is returned, which the B-side uses for business logic.If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.LivexxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty]].If the server encounters an error, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| lessonId | true | Long | Lesson ID |
| file | false | File | Uploaded file must not exceed 50MB. Supported formats: (ppt, pdf, pptx, doc, docx, wps, xls, xlsx). Only one of file or url needs to be provided. If both are provided, the file field takes precedence. |
| type | false | String | Conversion type. Default is normal conversion if not specified. Only ppt and pptx can be converted to animation; other file types are automatically converted to normal. If animation conversion fails, the type is automatically changed to normal. common: Convert to normal images. animate: Convert to animated effects. |
| docName | false | String | Document name. If not specified, the filename from the uploaded PPT file is used. The document name must not exceed 100 characters. |
| callbackUrl | false | String | Callback URL for successful document upload and conversion. |
| url | false | String | File URL (must be an accessible address). Only one of file or url needs to be provided. If both are provided, the file field takes precedence. |
Return Object Description
| Parameter | Type | Description |
|---|---|---|
| type | String | Conversion type. Default is normal conversion if not specified. Only ppt and pptx can be converted to animation; other file types are automatically converted to normal. If animation conversion fails, the type is automatically changed to normal. common: Convert to normal images. animate: Convert to animated effects. |
| fileId | String | File ID, returned on success. |
| status | String | Document status. normal: Normal. waitUpload: Waiting for upload. failUpload: Upload failed. waitConvert: Converting PPT. failConvert: PPT conversion failed. |
2. Query Uploaded Document List for a Lesson
Description
获取课节文档列表
接口地址(仅做说明使用):https://api.polyv.net/hi-class-api/open/file/v1/doc-list
Call Constraints
- API calls are rate-limited. Click here for details. For common call exceptions, click here.
Unit Test
@Test
public void testListDoc() throws IOException, NoSuchAlgorithmException {
VClassDocListRequest vClassDocListRequest = new VClassDocListRequest();
VClassDocListResponse vClassDocListResponse;
try {
vClassDocListRequest.setLessonId(super.createLesson());
vClassDocListResponse = new VClassFileServiceImpl().listDoc(vClassDocListRequest);
Assert.assertNotNull(vClassDocListResponse);
if (vClassDocListResponse != null) {
//to do something ......
log.debug("测试查询课节已上传文档列表成功 {}", JSON.toJSONString(vClassDocListResponse));
}
} 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 Description
On a successful request, a
VClassDocListResponseobject is returned, which the B-side uses for business logic.If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.LivexxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty]].If the server encounters an error, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| lessonId | true | Long | Lesson ID |
| status | false | String | Document status. If not specified, all statuses are queried. normal: Normal. waitUpload: Waiting for upload. failUpload: Upload failed. waitConvert: Converting PPT. failConvert: PPT conversion failed. |
| isShowUrl | false | String | Whether to display the original document URL. Default is not to display. Y: Yes. N: No. |
| currentPage | false | Integer | Page number, default is 1 [Corresponds to the page field in the API documentation]. |
| pageSize | false | Integer | Number of data items per page, default is 10 [Corresponds to the limit field in the API documentation]. |
Return Object Description
| Parameter | Type | Description |
|---|---|---|
| contents | Array | Document list [See Doc Parameter Description for details]. |
| pageSize | Integer | Number of data items per page, default is 10. |
| currentPage | Integer | Current page [Corresponds to the pageNumber field in the API documentation]. |
| totalItems | Integer | Total number of records. |
| totalPage | Integer | Total number of pages [Corresponds to the totalPages field in the API documentation]. |
Doc Parameter Description
| Parameter | Type | Description |
|---|---|---|
| fileId | String | File ID |
| fileName | String | File name |
| fileUrl | String | File URL |
| fileType | String | File type |
| totalPage | Integer | Total number of pages in the uploaded document. |
| channelId | String | Channel ID |
| status | String | Document status. If not specified, all statuses are queried. normal: Normal. waitUpload: Waiting for upload. failUpload: Upload failed. waitConvert: Converting PPT. failConvert: PPT conversion failed. |
| createTime | Date | Creation time |
| convertType | String | Conversion type. Default is normal conversion if not specified. Only ppt and pptx can be converted to animation; other file types are automatically converted to normal. If animation conversion fails, the type is automatically changed to normal. common: Convert to normal images. animate: Convert to animated effects. |
| previewImage | String | PPT preview thumbnail URL. |
| previewBigImage | String | PPT preview large image URL. |
| autoId | Integer | Document ID |
3. Delete Document
Description
删除课节文档接口
接口地址(仅做说明使用):https://api.polyv.net/hi-class-api/open/file/v1/delete
Call Constraints
- API calls are rate-limited. Click here for details. For common call exceptions, click here.
Unit Test
@Test
public void testDeleteDoc() throws IOException, NoSuchAlgorithmException {
VClassDeleteDocRequest vClassDeleteDocRequest;
Boolean vClassDeleteDocResponse;
try {
vClassDeleteDocRequest = VClassDeleteDocRequest.builder()
.lessonId(super.createLesson())
.fileId("5e4e4a18f2dcc89590bc3f8bc70c5da62771229common")
.build();
vClassDeleteDocResponse = new VClassFileServiceImpl().deleteDoc(vClassDeleteDocRequest);
Assert.assertTrue(vClassDeleteDocResponse);
if (vClassDeleteDocResponse) {
//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 Description
On a successful request, a
Booleanobject is returned, which the B-side uses for business logic.If request parameter validation fails, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.LivexxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty]].If the server encounters an error, a
PloyvSdkExceptionis thrown. The error message can be obtained viaPloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| lessonId | true | Long | Lesson ID |
| fileId | true | String | File ID(s). For multiple IDs, separate them with commas. This value can be obtained from the data.contents[0].fileId field of the response from the [Query Uploaded Document List for a Lesson] API. |
| currentPage | false | Integer | Page number, default is 1 [Corresponds to the page field in the API documentation]. |
| pageSize | false | Integer | Number of data items per page, default is 10 [Corresponds to the limit field in the API documentation]. |
Return Object Description
Entity returned after deleting a document.
