文档

新增媒体

更新时间:

向媒体库中新增媒体文件时,可以指定工作流ID触发工作流执行,对新增的媒体文件进行媒体处理。本文介绍通过Python SDK新增媒体并触发工作流执行的示例代码。

说明

如果上传的目录满足工作流触发条件,则会触发工作流执行,否则不触发。更多信息,请参见工作流的文件匹配规则

import os

from urllib.parse import quote
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.AddMediaRequest import AddMediaRequest

# 读取环境变量中设置的ACCESS_KEY   ACCESS_KEY_SECRET信息
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# region_id 为调用的服务地域ID,支持的地域参考 https://help.aliyun.com/document_detail/43248.html
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
bucket_name = '<your bucket name>'
# 文件object需要进行url编码
oss_object = 'mps-test/input/video.mp4'

request = AddMediaRequest()
request.set_FileURL("http://" + bucket_name + ".oss-cn-shanghai.aliyuncs.com/" + quote(oss_object))
request.set_MediaWorkflowId("829be3de95e957e341****")

response = client.do_action_with_exception(request)
# 输出打印
print(str(response, encoding='utf-8'))