# POLYV Web上传插件(V1.0)

使用POLYV Web上传插件，首先在页面上做一个上传按钮。

```
```

接下来，引用POLYV Web上传插件的js，初始化上传参数并新建一个上传示例。 上传参数解释： cataid：上传目录id； luping：开启视频课件优化处理，对于上传录屏类视频清晰度有所优化； state：自定义参数，可以通过回调通知接口抓取到该字段； keepsource：源文件播放（不对源文件进行编码）。

```


var obj = {
    uploadButtton: "upload",   //打开上传控件按钮id
	userid : "sl8da4jjbx",
	ts : "1470708600000",
	hash : "66983f12660727d5767ca397f52e54ca",
    cataid:'1352947888026',
	sign: "fa36e05987b4b7c3b150003dd1122b30",
    luping: 1, //开启课件优化
	extra: {
	    state: 'hellopolyv',//自定义参数，可以通过回调通知接口抓取到该字段
        keepsource: '1' //源文件播放（不对源文件进行编码）
	        }
   }
    var upload = new PolyvUpload(obj);
```

hash的值，是根据将13位的毫秒级时间戳和writeToken按照顺序拼凑起来的字符串进行MD5计算得到的值，如：

```
```

sign的值，是根据将secretkey和13位的毫秒级时间戳按照顺序拼凑起来的字符串进行MD5计算得到的值，如：

```
```

由于时间戳的有效期为3分钟，为了避免停留在同一个页面3分钟后，无法在同一个页面使用该上传插件的功能，需要客户端页面每隔3分钟刷新获取最新的ts、hash、sign的值，并调用插件的update方法更新数据。

```
//前端js每隔3分钟去调用reload.php去获取最新的ts、hash、sign
//并通过上传插件的update方法去更新数据

    setInterval(function(){
       $.getJSON( "reload.php?callback=?", function( data ) {
        upload.update(data);

       });
     },3*60*1000);
```

```
//服务端reload.php的源码示例，用来输出ts、sign、hash的值


({
ts:'',
sign:'',
hash:''
});
```

如果需要在前端页面中显示服务器返回的响应信息，可以点击”上传”——“视频列表”——“返回视频信息”触发response事件，需要在初始化上传参数中加上response事件参数，并在页面中加上对应的文本框元素。如果还需要在点击“返回视频信息”按钮时自动关闭弹窗，可以加上upload.closeWrap()方法。

```
var obj = {
	response: function(json) {  
		var scriptdata = "" +
		"var player = polyvObject('#plv_" + json.vid + "').videoPlayer({\n" +
									"'width':'690',\n"+
									"'height':'385',\n"+
									"'vid' : '" + json.vid + "'"+
								"});<\/script>";
								
		document.getElementById("textbody").value = document.getElementById("textbody").value + scriptdata;
		
		//如果需要关闭窗口
		upload.closeWrap();
		
	}
}</pre>
点击”上传”——“视频列表”——“返回视频信息”，可以在文本框看到POLYV云平台返回的response事件函数中的data数据。
示例可点击参考:
示例源码：
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://polyv.gitbook.io/document/docs/unclassified/2013/dc9d95dd349f2603db589095219c2beb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
