Upload Danmaku File
Updated: 2025-01-14 15:58:50
API Description
1、通过视频id上传弹幕文件
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/danmu/{userid}/upload
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended to ensure security. API calls are subject to rate limits. See details
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| ptime | true | Long | Current time in milliseconds, valid within 3 minutes |
| sign | true | String | Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical for communication data security. It must never be stored or used directly on the client side. All API calls must be relayed through your own server to the POLYV server for response data. See Signature Generation Rules |
| vid | true | String | Video ID |
| file | true | File | Danmaku file, supports UTF-8 encoding |
Example
http://api.polyv.net/v2/danmu/1b448be323/upload
Form parameters:
vid=1b448be323b68b2999802799a98dba54_1&sign=B573120BDF7F320DA32542779D6AC1CD7D6E23C9&ptime=1617176768530
The danmaku file is uploaded to the server as an HTTP binary stream.
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 indicates success, non-200 indicates failure. See Global Error Codes |
| status | String | Response status text |
| message | String | Response description. When code is 400 or 500, provides additional error details |
| data | Integer | On success, returns the number of danmaku entries uploaded. On failure, returns empty |
Error Code List
| Error Code | message | Description |
|---|---|---|
| 400 | sign can not be empty. | Signature is empty |
| 400 | ptime is too old. | Timestamp expired |
| 400 | ptime is illegal. | Invalid timestamp format or exceeds current time by 3 minutes |
| 400 | Could not find user by userId. | User ID does not exist |
| 400 | the sign is not right. | Incorrect signature |
| 400 | vid doesn't exist. | Video does not exist |
| 400 | Please Use UTF-8 for SRT files | File format or encoding issue |
Java Request Example
For quick integration, download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own project. The test case files HttpUtil.java and VodSignUtil.java are included in the download.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pooling.
private static final Logger log = LoggerFactory.getLogger(VodVideoManagementTest.class);
/**
* 上传弹幕
*/
@Test
public void testUploadDanmuFile() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/danmu/"+userId+"/upload";
String vid = "1b448be323b68b2999802799a98dba54_1";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
File file = new File(getClass().getResource("/barrage/srt(zh_CN).srt").getPath());
Map<String, File> fileMap = new HashMap<>();
fileMap.put("file", file);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFile(url, requestMap, fileMap, null);
log.debug("测试上传弹幕,{}", response);
//do somethings
}
Response Example
For global system error codes, see Global Error Codes
Success Example
{
"code": 200,
"status": "success",
"message": "success",
"data": 5
}
Error Example
Timestamp expired:
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
Signature error:
{
"code": 400,
"status": "error",
"message": "the sign is not right.",
"data": ""
}
File name is empty:
{
"code": 400,
"status": "error",
"message": "title can't be empty",
"data": ""
}
File is empty:
{
"code": 400,
"status": "error",
"message": "file can't be empty",
"data": ""
}
