When you add a media file to a media library, you can specify a workflow ID to trigger a workflow that processes the media file. This topic provides PHP SDK sample code for adding a media file and triggering a workflow.
Prerequisites
MPS SDK for PHP is installed and configured. For more information, see MPS SDK for PHP. To obtain more information about the SDK and view examples on how to use the SDK to call API operations, visit OpenAPI Explorer.
Add a media file
Call the AddMedia operation to add a media file to a media library. For more information about the request and response parameters, see AddMedia. Sample request:
A workflow is triggered only if the media library meets the triggering rules of that workflow. For more information, see Workflow triggering rules for files.
<?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****"; # The ID of the media workflow. You can view the workflow ID in the MPS console.
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* We recommend that you set the protocol parameter to HTTPS in a production environment.
*/
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();