All Products
Search
Document Center

Media upload

Last Updated: Jul 11, 2019

This topic describes how to use the Node.js server SDK to call server operations, for example, to obtain the upload URL and credential and register media asset information. To upload complete media files, you can use the client upload SDK together with the upload URL and credential.

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Obtain the video upload URL and credential

For more information about the request and response parameters, see CreateUploadVideo.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("CreateUploadVideo", {
    Title: 'this is a sample',
    FileName: 'filename.mp4'
}, {}).then(function (response) {
    console.log('VideoId = ' + response.VideoId);
    console.log('UploadAddress = ' + response.UploadAddress);
    console.log('UploadAuth = ' + response.UploadAuth);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Refresh the video upload credential

For more information about the request and response parameters, see RefreshUploadVideo.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("RefreshUploadVideo", {
    VideoId: 'VideoId'
}, {}).then(function (response) {
    console.log('UploadAddress = ' + response.UploadAddress);
    console.log('UploadAuth = ' + response.UploadAuth);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Obtain the image upload URL and credential

For more information about the request and response parameters, see CreateUploadImage.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("CreateUploadImage", {
    ImageType: 'cover',
    ImageExt: 'jpg'
}, {}).then(function (response) {
    console.log('ImageId = ' + response.ImageId);
    console.log('ImageURL = ' + response.ImageURL);
    console.log('UploadAddress = ' + response.UploadAddress);
    console.log('UploadAuth = ' + response.UploadAuth);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Obtain the upload URL and credential for an attached media asset

For more information about the request and response parameters, see CreateUploadAttachedMedia.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("CreateUploadAttachedMedia", {
    BusinessType: 'watermark',
    MediaExt: 'gif',
    Title: 'this is a sample'
}, {}).then(function (response) {
    console.log('MediaId = ' + response.MediaId);
    console.log('MediaURL = ' + response.MediaURL);
    console.log('UploadAddress = ' + response.UploadAddress);
    console.log('UploadAuth = ' + response.UploadAuth);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Upload multiple videos based on mezzanine file URLs

For more information about the request and response parameters, see UploadMediaByURL.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

var url = 'http://xxxx.mp4';
var uploadMetadatas = [{
    SourceUrl: url,
    Title: 'upload by url sample'
}];
client.request("UploadMediaByURL", {
    UploadURLs: url,
    UploadMetadatas: JSON.stringify(uploadMetadatas)
}, {}).then(function (response) {
    console.log('UploadJobs = ');
    console.log(response.UploadJobs);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Register media asset information

For more information about the request and response parameters, see RegisterMedia.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

var url = 'http://xxxx.mp4';
var registerMetadatas = [{
    FileURL: url,
    Title: 'this is a sample'
}];
client.request("RegisterMedia", {
    RegisterMetadatas: JSON.stringify(registerMetadatas)
}, {}).then(function (response) {
    if (response.FailedFileURLs && response.FailedFileURLs.length > 0){ 
        for (var i=0; i<response.FailedFileURLs.length; i++) { 
            console.log('FailedFileURL = ' + response.FailedFileURLs[i]);
        }
    }
    if (response.RegisteredMediaList && response.RegisteredMediaList.length > 0){ 
        for (var i=0; i<response.RegisteredMediaList.length; i++) { 
            console.log('MediaId = ' + response.RegisteredMediaList[i].MediaId);
            console.log('FileURL = ' + response.RegisteredMediaList[i].FileURL);
            console.log('NewRegister = ' + response.RegisteredMediaList[i].NewRegister);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});