Polyv Help Center

Help Center

Upload Document to a Channel

Updated: 2024-10-22 11:02:08

API Description

1、上传频道文档接口
2、(channelId, type, docName, callbackUrl, timestamp, appId, url)参与sign签名,并和sign一起通过post表单传递,文件通过二进制流提交到服务器端。
3、接口支持https协议

API URL

http://api.polyv.net/live/v3/channel/document/upload-doc

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. Click for details

  2. The uploaded file must not exceed 200MB. Supported formats are (ppt, pdf, pptx, doc, docx, wps).

  3. Only one of file and url needs to be provided. If both are provided, the file field 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 never be used directly on the client side. All APIs must be called through your own server to relay requests to the POLYV server for response data. See: Signature Generation Rules
channelId true String Channel ID
file false File Uploaded file must not exceed 200MB. Supported formats: (ppt, pdf, pptx, doc, docx, wps). Only one of file and url needs to be provided. If both are provided, the file field takes precedence.
type false 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 automatically changed to normal.
common: Convert to normal images
animate: Convert to animated effects
docName false String Document name. Default uses the filename from the uploaded ppt file. 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 accessible). Only one of file and url needs to be provided. If both are provided, the file field takes precedence. Uploaded file must not exceed 200MB.

Example

http://api.polyv.net/live/v3/channel/document/upload-doc

Form Parameters:

docName=test&appId=frlr1zazn3&sign=FC2296E942D2DB118C64C11AD941445D&callbackUrl=http%3A%2F%2Fwww.baidu.com&type=common&channelId=1965681&timestamp=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 document upload information. See: Data Parameter Description. On failure, this 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 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

Callback Description

Real-time callback for PPT conversion to images, animations, etc., notifying 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&timestamp=1603506240000&channelId=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
channelId String Channel ID
timestamp Long 13-digit millisecond timestamp
sign String Encrypted string for verification. Generation rule: md5(channelId+timestamp)

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download source code. After downloading, add it to your own source code project. 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(ChannelDocTest.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/live/v3/channel/document/upload-doc";
    String channelId = "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("channelId",channelId);
    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": ""
}
联系客服,在线咨询