All Products
Search
Document Center

ApsaraVideo Media Processing:Add a video file

Last Updated:Aug 28, 2023

This topic provides the sample code for using ApsaraVideo Media Processing (MPS) SDK for PHP to add a video file to a media library.

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
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // The ID of the region in which your MPS service is deployed.
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}

try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = addMedia($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function addMedia($client) {
    $request = new Mts\AddMediaRequest();
    $request->setFileURL("http://<bucket name>.oss-cn-shanghai.aliyuncs.com/media/video.mp4");
    $request->setMediaWorkflowId("829bed036de957e3421****");
    return $client->getAcsResponse($request);
}