All Products
Search
Document Center

ApsaraVideo Media Processing:Add a media file

Last Updated:Aug 28, 2023

This topic provides an example on how to call the AddMedia operation that is encapsulated in ApsaraVideo Media Processing (MPS) SDK for PHP to add a media file to a media library.

Prerequisites

MPS SDK for PHP is installed and configured. For more information, see Overview. 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

You can call the AddMedia operation to add a media file to a media library. For more information about the request and response parameters, see AddMedia. The following code shows a sample request:

Note

If the media library meets the triggering rules of a workflow, the workflow is triggered. Otherwise, the workflow is not triggered. 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();