All Products
Search
Document Center

Intelligent Media Services:Obtain the URL and credential for uploading a media asset

Last Updated:Nov 28, 2024

This topic describes the sample code that is used to call an API operation by using the server SDK to obtain the URL and credential for uploading a media asset.

Sample code

You can use Alibaba Cloud OpenAPI Explorer to perform online debugging.

import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Credential, { Config } from '@alicloud/credentials';
const Client = require('@alicloud/ice20201109').default;

// An AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M. 
// In this example, the AccessKey ID and AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-0-node-js-sdk/?spm=a2c63.p38356.0.0.3b2b3ccarBQ6QC. 

const cred = new Credential();
const iceClient = new Client(new $OpenApi.Config({
  credential: cred,
  endpoint: 'ice.cn-shanghai.aliyuncs.com'
}));

// To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised. 
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// Obtain the URL and credential for uploading a media asset. 
iceClient.createUploadMedia({
    fileInfo: "{\"Type\":\"video\",\"Name\":\"test\",\"Size\":123,\"Ext\":\"mp4\"}",
    mediaMetaData: "{\"Title\":\"UploadTest\",\"Description\":\"UploadTest\",\"BusinessType\":\"general\"}",
    uploadTargetConfig: "{\"StorageType\":\"oss\",\"StorageLocation\":\"testbucket.oss-cn-shanghai.aliyuncs.com\"}",
}).then(function (data) {
    console.log(data.body);
}, function (err) {
    console.log('Error:' + err);
});

Related API operations

CreateUploadMedia