向媒体库中新增媒体文件时,可以指定工作流ID触发工作流执行,对新增的媒体文件进行媒体处理。本文介绍通过PHP SDK新增媒体并触发工作流执行的示例代码。
前提条件
新增媒体
调用AddMedia新增媒体,接口参数和返回字段详细信息请参见新增媒体,调用示例如下:
说明
如果上传的目录满足工作流触发条件,则会触发工作流执行,否则不触发。详细触发规则,请参见工作流的文件匹配规则。
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use AlibabaCloud\Darabonba\Env\Env;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\AddMediaRequest;
class Sample {
private $mediaWorkflowId = "43edb70134fa61a2c****"; #工作流ID 可在控制台创建/查看
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* 正式环境下 建议 protocol = "HTTPS";
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
/**
* @return void
*/
public static function main(){
$sample = new Sample;
$client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
$request = new AddMediaRequest([
"fileURL" => "http://<bucket name>.oss-cn-shanghai.aliyuncs.com/media/video.mp4",
"title" => "title",
"description" => "description",
"mediaWorkflowId" => $sample->mediaWorkflowId
]);
$response = $client->addMedia($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
文档内容是否对您有帮助?