全部产品

媒体上传

更新时间:2020-11-30 17:52

本文档提供了Node.js SDK媒体上传相关功能的API调用示例,包含获取上传地址和凭证、注册媒资信息、URL批量拉取上传等。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取视频上传地址和凭证

调用CreateUploadVideo接口,完成获取视频上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadVideo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

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);
});

刷新视频上传凭证

调用RefreshUploadVideo接口,完成刷新视频上传凭证功能。

接口参数和返回字段请参见RefreshUploadVideo。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

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);
});

获取图片上传地址和凭证

调用CreateUploadImage接口,完成获取图片上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadImage。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

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);
});

获取辅助媒资上传地址和凭证

调用CreateUploadAttachedMedia接口,完成获取辅助媒资上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadAttachedMedia。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

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);
});

URL批量拉取上传

调用UploadMediaByURL接口,完成URL批量拉取上传功能。

接口参数和返回字段请参见UploadMediaByURL。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

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);
});

注册媒资信息

调用RegisterMedia接口,完成注册媒资信息功能。

接口参数和返回字段请参见RegisterMedia。调用示例如下:

// 请求示例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

var url = 'http://192.168.0.0/16.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);
});