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 json
import os
import sys
from typing import List
from alibabacloud_ice20201109.client import Client as ICE20201109Client
# Import Alibaba Cloud IMS SDK.
from alibabacloud_ice20201109 import models as ice20201109_models
# Import a client for credentials and SDKs of cloud services and create an alias for the client.
from alibabacloud_credentials.client import Client as CredClient
# Import the core package of Alibaba Cloud SDKs.
from alibabacloud_tea_openapi.models import Config
#######Required dependencies#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:
# Initialize the client.
@staticmethod
def create_client(region: str) -> ICE20201109Client:
# Use the default credential to initialize the credentials client.
cred = CredClient()
config = Config(credential = cred)
# Specify the endpoint of the cloud service.
config.endpoint = 'ice.' + region + '.aliyuncs.com'
# Use the credentials client to initialize the ECS SDK client.
return ICE20201109Client(config)
# @staticmethod
# def create_client(
# access_key_id: str,
# access_key_secret: str,
# region: str,
# ) -> ICE20201109Client:
# 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.
# config = open_api_models.Config(
# # Required. Specify your AccessKey ID.
# access_key_id = access_key_id,
# # Required. Specify your AccessKey secret.
# access_key_secret = access_key_secret
# )
# # Specify the endpoint that you want to access.
# config.endpoint = 'ice.' + region + '.aliyuncs.com'
# return ICE20201109Client(config)
# Read command line parameters.
@staticmethod
def main() -> None:
region = 'cn-shanghai'
# Initialize the client.
client = Sample.create_client(region)
request = ice20201109_models.CreateUploadMediaRequest(
file_info='{"Type":"video","Name":"test","Size":123,"Ext":"mp4"}',
media_meta_data='{"Title":"UploadTest","Description":"UploadTest","BusinessType":"general"}',
upload_target_config='{"StorageType":"oss","StorageLocation":"outin-xxxxxx.oss-' + region + '.aliyuncs.com"}'
)
response = client.create_upload_media(request)
print('[LOG]', json.dumps(response.to_map()))
if __name__ == '__main__':
Sample.main()