Upload Document to a Lesson
Interface Description
1、上传课节文档接口
2、(lessonId, type, docName, callbackUrl, url, timestamp, appId)参与sign签名,并和sign一起通过post表单传递,文件通过二进制流提交到服务器端。
3、接口支持https协议
Interface URL
http://api.polyv.net/hi-class-api/open/file/v1/upload-doc
Request Method
POST
Interface Constraints
The interface supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. Interface calls have frequency limits. See details
The uploaded file must not exceed 50MB, and the allowed formats are (ppt, pdf, pptx, doc, docx, wps).
Only one of
fileandurlneeds to be passed. If bothurlandfileare passed, thefilefield takes precedence.
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | true | String | Account appId [See Get Secret Key] |
| timestamp | true | Long | Current 13-digit millisecond timestamp, valid for 3 minutes |
| sign | true | String | Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be used directly on the client side. All APIs must be called through the customer's own server to relay to the POLYV server for response data. [See Signature Generation Rules] |
| lessonId | true | String | Lesson ID |
| file | false | File | Uploaded file must not exceed 50MB, allowed formats: (ppt, pdf, pptx, doc, docx, wps). Only one of file and url needs to be passed. If both are passed, file 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 animation effects |
| docName | false | String | Document name. If not specified, the file name from the uploaded ppt is used as the document name. 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 and url needs to be passed. If both are passed, file takes precedence. |
Example
http://api.polyv.net/hi-class-api/open/file/v1/upload-doc
Form parameters:
docName=test&appId=frlr1zazn3&sign=FC2296E942D2DB118C64C11AD941445D&callbackUrl=http%3A%2F%2Fwww.baidu.com&type=common&lessonId=1965681×tamp=1621842842327
Response Parameter Description
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 indicates success, non-200 indicates failure [See Global Error Description] |
| status | String | Response status text |
| message | String | Response description. When code is 400 or 500, provides additional error details. |
| data | Object | On success, contains information about the uploaded document [See Data Parameter Description]. On failure, it is empty. |
Data Parameter Description
| Parameter | Type | Description |
|---|---|---|
| type | String | Conversion type. Default is normal 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 changed to normal. common: Convert to normal images animate: Convert to animation 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 |
Callback Description
Real-time callback for PPT conversion to images, animations, etc., to notify users of upload and conversion task results.
Principle
Sends a GET request to the user's server via the HTTP interface (set callbackUrl) to push the merge result to the user's server.
Example
Example: http://abc.com/test.do?status=normal×tamp=1603506240000&lessonId=xxxx&fileId=xxx&sign=xxdxxxxx
| Parameter | Type | Description |
|---|---|---|
| status | String | File conversion status ("normal": Normal, "failConvert": PPT conversion failed) |
| fileId | String | File ID, returned on success |
| lessonId | String | Lesson ID |
| timestamp | Long | 13-digit millisecond timestamp |
| sign | String | Encrypted string for verification, generated by rule md5(lessonId+timestamp) |
Java Request Example
For quick integration of basic code, download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own project source code. The test cases include HttpUtil.java and LiveSignUtil.java in the downloaded file.
It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(LessonDocTest.class);
/**
* 上传文档到某个课节
* @throws IOException
*/
@Test
public void testUploadDoc() throws IOException, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId=super.appId;
String appSecret=super.appSecret;
String userId = super.userId;
String timestamp=String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/hi-class-api/open/file/v1/upload-doc";
String lessonId = "1965681";
String type = "common";
String docName = "test";
String callbackUrl = "http://www.baidu.com";
String path = getClass().getResource("/file/").getPath() + "report.pdf";
File file = new File("D:/test.pdf");
//http 调用逻辑
Map<String,String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp",timestamp);
requestMap.put("lessonId",lessonId);
Map<String,File> fileMap = new HashMap<>();
fileMap.put("file",file);
requestMap.put("type",type);
requestMap.put("docName",docName);
requestMap.put("callbackUrl",callbackUrl);
requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
String response = HttpUtil.postFile(url, requestMap,fileMap,"utf-8");
log.info("测试上传文档到某个课节:{}",response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code":200,
"status":"success",
"message":"",
"data":{
"type":"common",
"fileId":"39e6bd3fe674c952815ad1a09c66e1061965681common",
"status":"waitConvert"
}
}
Error Example
{
"code": 400,
"status": "error",
"message": "invalid signature.",
"data": ""
}
