Upload a media asset by URL

Updated at:

Upload media assets by URL by calling an OpenAPI operation through a server-side SDK.

Usage notes

To configure environment variables, see Configure environment variables in Linux, macOS, and Windows.

Sample code

To debug this operation online, use the Alibaba Cloud OpenAPI Developer Portal.

<?php

require_once '../vendor/autoload.php';

use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models;
use AlibabaCloud\SDK\ICE\V20201109\Models\UploadMediaByURLRequest;
use Darabonba\OpenApi\Models\Config;

try {

    // An AccessKey of an Alibaba Cloud account has full access permissions to all APIs. Use a Resource Access Management (RAM) user for API calls and routine O&M.
    // This example shows how to store the AccessKey ID and AccessKey secret in environment variables. For more information, see https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-php-access-credentials
    $credential = new Credential([]);
    $config = new Config([
     'credential' => $credential,
     'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
    ]);
    // To hard-code the AccessKey ID and AccessKey secret, use the following code. However, do not store your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and compromise the security of all resources in your account.
    // $config->accessKeyId = '<yourAccessKeyId>';
    // $config->accessKeySecret = '<yourAccessKeySecret>';
    $client = new ICE($config);

    $request = new UploadMediaByURLRequest();
    $request->uploadURLs = "https://test.com/test.mp4";
    $request->uploadTargetConfig = "{\"StorageType\":\"oss\",\"StorageLocation\":\"out-****.oss-cn-shanghai.aliyuncs.com\"}";
    $response = $client->uploadMediaByURL($request);
    echo json_encode($response->body);

} catch (TeaUnableRetryError $e) {
    var_dump($e);
}

Related API operations

UploadMediaByURL