Polyv Help Center

Help Center

Upload Plugin 2.0

Updated: 2024-11-21 11:16:50

Notes:

  1. This document briefly describes how to use the POLYV web upload plugin from a user's perspective.
  2. The usage of V2.0 is completely identical to V1.0, so there is no need to change the original API calls or logic. Simply replace the call address of polyv-upload.js. (V2.0 is recommended)

1. Features:

  1. File Upload
    1. Before uploading, you can select a category, add tags, choose video optimization processing, modify the file name and file description, etc.
    2. You can set a default upload directory.
    3. You can set whether to encode the source file.
    4. Supports resumable upload. If the network is interrupted or the browser restarts due to a failure, the same file can resume uploading from the breakpoint. (This feature is only supported in browsers >= IE10 and mainstream browsers.)
    5. Supports selecting multiple files simultaneously and displays upload progress.
  2. View Videos
    1. View the video list.
    2. Search for videos by title keywords.
    3. Retrieve specific video information.
    4. Change the cover image. a. Upload a new image as the cover. b. Select a video screenshot as the cover. c. Select a recently uploaded image as the cover.
  3. Option to display only the "Upload List", only the "Video List", or both.
  4. Can call interfaces (response, uploadSuccess, uploadFail) to return video information.
  5. Provides methods to open and close the plugin.

2. Browser Support

  • Supports most mainstream browsers. IE is compatible with IE9 and above.
  • In browsers that support HTML5 new features, resumable upload is supported, and files up to 30GB can be uploaded.
  • Conversely, in browsers that do not support HTML5 new features (e.g., IE9), resumable upload is not supported, and the maximum file size is 2GB.

3. Getting Started Guide:

1. First, add a button to the page that calls the plugin:

<input type="button" id="upload" value="上传"></input>

2. Include the POLYV upload plugin JS file:

<script src="//static.polyv.net/file/plug-in-v2/polyv-upload.min.js"></script>

3. Add a script to initialize the upload parameters and create a new upload instance.

var obj = {
    uploadButtton: 'upload',
    userid: data.userid,
    ts: data.ts,
    hash: data.hash,
    sign: data.sign,
    component: 'all',
    cataid: 1499657507273,
    luping: '1',
    extra: {
        keepsource: 1,
    }
};
upload = new PolyvUpload(obj);

Run Online

4. Periodically update parameters like sign: The ts, hash, and sign parameters in the upload configuration have a time limit. You need to update the parameters every 3 minutes. Use the update(data) method to update them. If the upload parameters include the correct requestUrl parameter, the plugin can automatically update the sign and other values internally.

5. Explanation of Upload Parameters: (For more details, please refer to the documentation below.)

  • uploadButtton: The ID of the button that opens the upload control.
  • userid: You can find your userid in the "Cloud Video" backend -> "Settings" -> "API Interface" page.
  • ts: A 13-digit millisecond timestamp.
  • hash: The MD5 hash value calculated from the string formed by concatenating ts and writeToken in order.
  • sign: The MD5 hash value calculated from the string formed by concatenating secretkey and ts in order.
  • component: Set to 'all' to display both the upload list and the video list.
  • cataid: The upload directory ID. '1' represents the default category.
  • luping: Enables video courseware optimization processing, which improves the clarity of uploaded screen recording videos.
  • keepsource: Plays the source file (does not encode the source file). Setting this to 1 means playing the source file.

6. Code Example for Getting User Information (PHP):

/* 
说明:以下的userid、secretkey、writeToken、readToken可以在“云点播”后台->“设置”->“API接口”页面中找到。
*/
$userid = "your userid";
$secretkey = "your sercrety";
$writeToken = "your writeToken";
$readToken = "your readToken";

$ts = time() * 1000;
$hash = md5($ts . $writeToken);
$sign = md5($secretkey . $ts);

4. Usage Documentation

1. Upload Parameters options

Parameter Description Type Required
uploadButtton The ID of the button that opens the upload plugin. String Required
userid You can find your userid in the "Cloud Video" backend -> "Settings" -> "API Interface" page. String Required
ts A 13-digit millisecond timestamp. Needs to be updated every 3 minutes using update(). Number Required (if requestUrl parameter is not set)
hash The MD5 hash value calculated from the string formed by concatenating ts and writeToken (found in the "Cloud Video" backend -> "Settings" -> "API Interface" page) in order. Needs to be updated every 3 minutes using update().
Do not convert to uppercase during MD5.
String Required (if requestUrl parameter is not set)
sign The MD5 hash value calculated from the string formed by concatenating secretkey (found in the "Cloud Video" backend -> "Settings" -> "API Interface" page) and ts in order. Needs to be updated every 3 minutes using update().
Do not convert to uppercase during MD5.
String Required (if requestUrl parameter is not set)
requestUrl The request URL for the plugin to periodically update the sign information internally. String Required (if ts, hash, sign parameters are not set)
component The component content to display. 'videoList' (only video list), 'uploadList' (only upload list), or 'all' (both upload and video lists). String Optional, default value 'all'
cataid The upload directory ID. If not provided, the default category is used. String Optional, default value '1'
luping Enables video courseware optimization processing, which improves the clarity of uploaded screen recording videos. '0' (disabled) or '1' (enabled). String Optional, default value '0'
defaultTagPlaceholder Custom placeholder for the tag input field. String Optional
defaultDescPlaceholder Custom placeholder for the video description input field. String Optional
fileLimit The maximum size of a single video file in bytes. No limit by default. Number Optional
fileLimitTips The prompt message when the file size exceeds the limit. Default: "The video file is too large, please select another one." String Optional
fileNumberLimit The maximum number of files that can be uploaded at once. No limit by default. Number Optional
fileNumberLimitTips The prompt message when the file count exceeds the limit. Default: "The number of files uploaded at once cannot exceed ${fileNumberLimit}." String Optional
fileTypeLimit File type restrictions. Enter file extensions, separated by commas (e.g., "avi,mp4"). Supported extensions: avi, mpg, mp4, flv, wmv, mov, 3gp, mkv, mp3, wav, m4v, webm. String Optional, defaults to common audio/video types.
batchFileSizeLimit The total size limit for a single batch of files selected for upload, in bytes. Number Optional
batchFileSizeLimitTips The prompt message when the total file size exceeds the limit. String Optional, default: "The total size of the files to be uploaded exceeds the limit, please select again."
width The width of the dialog box in pixels. Minimum value: 900. Number Optional, default value 1000
height The height of the dialog box in pixels. Minimum value: 500. Number Optional, default value 600
config Upload configuration. (Can include the following 2 items) Object Optional
config.parallel The concurrency number for chunked uploads. Number Optional, default value 5
config.useCDNDomain Whether to use a CDN domain for file uploads. Boolean Optional, default value false
region Sets the upload region. String Optional, default value 'line1'
extra (Can include the following 1 item) Object Optional
extra.keepsource Whether to play the source file (do not encode the source file). Can be set to 0 (encode the source file) or 1 (play the source file). Number Optional, default value 0
extra.state Custom user information. If this field is submitted, it will be transparently returned in the server-side upload completion callback. String Optional, default value 0
hiddenControlWidget Control parameters for hiding specific widgets. If not provided, all widgets are displayed by default. (Can include the following 3 items) Object Optional
hiddenControlWidget.cateSelector Whether to hide the category selector. When hidden, the upload directory uses the cataid parameter value. Boolean Optional, default value false
hiddenControlWidget.videoTagInput Whether to hide the tag input field. Boolean Optional, default value false
hiddenControlWidget.coursewareRefine Whether to hide the courseware optimization option. When hidden, the luping parameter value is used. Boolean Optional, default value false
uploadSuccess Callback function triggered when a file upload is complete. The callback parameter is fileData. Function Optional
uploadFail Callback function triggered when a file upload fails. The callback parameter is err. Function Optional
response Callback function for returning information about a specified video. Function Optional

2. Methods

1. update(data)

Used to update the ts, hash, and sign information.

2. closeWrap()

Closes the plugin.

3. openWrap()

Opens the plugin.

4. destroy()

Destroys the instance.

5. setParams(Object|String[, value])

Updates optional configuration parameters.

setParams Parameter Description:

  • When the first parameter is of type Object, multiple plugin parameters can be updated simultaneously. For example:
upload.setParams({
    cataid: 233333,
    luping: 1,
    defaultTagPlaceholder: '标签文字说明'
});
  • When the first parameter is of type String, only a single plugin parameter is updated. The first parameter is the name of the plugin parameter to update, and the value parameter is required. For example:
upload.setParams('cataid', 233333);

setParams Updatable Parameters: component, luping, defaultTagPlaceholder, defaultDescPlaceholder, fileLimit, fileLimitTips, fileNumberLimit, fileNumberLimitTips, width, height, extra

5. Demo Download

Demo Download: POLYV Web Upload Plugin Source Code

6. Version History

v2.1.0

  • Added file type validation for uploads.
  • Added parameter support for modifying the upload region.
  • Added parameter support for limiting the total size of a single batch upload.
联系客服,在线咨询