TcVod
. You can choose either of the two ways below:<script src="./vod-js-sdk-v6.js"></script>
src
to the local path of the source code.<script src="https://cdn-go.cn/cdn/vod-js-sdk-v6/latest/vod-js-sdk-v6.js"></script>
// Run `npm install vod-js-sdk-v6`, and use the command below to import the SDK directly on the page:import TcVod from 'vod-js-sdk-v6'
function getSignature() {return axios.post(url).then(function (response) {return response.data.signature;})};
url
is the URL of your signature distribution service. For more information, see the Guide for upload from a client.signature
, see Signature for Upload from Client.// If the SDK is imported using the `import` command, run `new TcVod(opts)`.// If the SDK is imported using a script tag, use `new TcVod.default(opts)`.const tcVod = new TcVod.default({getSignature: getSignature // The function to get the upload signature})const uploader = tcVod.upload({mediaFile: mediaFile, // The media file (video, audio, or image), whose data type is file.})uploader.on('media_progress', function(info) {console.log(info.percent) // The upload progress})// Callback of the result// type doneResult = {// fileId: string,// video: {// url: string// },// cover: {// url: string// }// }uploader.done().then(function (doneResult) {// Deal with doneResult}).catch(function (err) {// Deal with error})
opts
in new TcVod(opts)
refers to parameters of the TcVod
API. For details, see API Description.const uploader = tcVod.upload({mediaFile: mediaFile,coverFile: coverFile,})uploader.done().then(function (doneResult) {// Deal with doneResult})
const uploader = tcVod.upload({mediaFile: mediaFile,coverFile: coverFile,})// When the video upload is completeduploader.on('media_upload', function(info) {uploaderInfo.isVideoUploadSuccess = true;})// The video upload progressuploader.on('media_progress', function(info) {uploaderInfo.progress = info.percent;})// When the thumbnail upload is completeduploader.on('cover_upload', function(info) {uploaderInfo.isCoverUploadSuccess = true;})// The thumbnail upload progressuploader.on('cover_progress', function(info) {uploaderInfo.coverProgress = info.percent;})uploader.done().then(function (doneResult) {// Deal with doneResult})
const uploader = tcVod.upload({mediaFile: mediaFile,coverFile: coverFile,})uploader.cancel()
Parameter | Required | Type | Description |
getSignature | Yes | Function | The function used to get the upload signature. |
appId | No | number | If this parameter is set, it will be carried by the built-in statistical report system. |
reportId | No | number | If this parameter is set, it will be carried by the built-in statistical report system. |
Parameter | Required | Type | Description |
mediaFile | No | File | The media file (video, audio, or image). |
coverFile | No | File | The thumbnail file. |
mediaName | No | string | The filename, which will overwrite the filename in the metadata. |
fileId | No | string | The ID of the new thumbnail file. |
reportId | No | number | If this parameter is set, it will be carried by the built-in statistical report system and will overwrite the settings in the constructor. |
fileParallelLimit | No | number | The maximum number of concurrent uploads allowed in the same instance. Default value: 3. |
chunkParallelLimit | No | number | The maximum number of upload parts allowed for the same file. Default value: 6. |
chunkRetryTimes | No | number | The maximum number of retry attempts for multipart upload. Default value: 2 (three upload requests in total). |
chunkSize | No | number | The part size (bytes) for multipart upload. Default value: 8388608 (8 MB). |
progressInterval | No | number | The interval (ms) of sending the onProgress callback. Default value: 1000. |
Event Name | Required | Description |
media_upload | No | The media file is successfully uploaded. |
cover_upload | No | The thumbnail is successfully uploaded. |
media_progress | No | The media file upload progress. |
cover_progress | No | The thumbnail file upload progress. |
input
tag and set type
to file
.uploader.cancel()
, and to resume an upload after pause, call tcVod.upload
. Note that when you use tcVod.upload
to resume an upload, you need to pass in the same parameters used when you initiate the upload (you can use a global variable to save the parameters when you initiate the upload and delete them after upload.)https:
upload?
Yes, it does. The SDK uses http:
for upload on HTTP pages and https:
on non-HTTP pages.
Was this page helpful?