Obtain a media asset upload URL and credentials
Updated at:
After reading this article, you will learn the sample code for obtaining the media upload URL and credential by calling the OpenAPI of the server SDK.
Sample code
You can debug this operation online in 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\SubmitMediaProducingJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetMediaProducingJobRequest;
use Darabonba\OpenApi\Models\Config;
try {
// An AccessKey of an Alibaba Cloud account provides full access to all API operations. Use a Resource Access Management (RAM) user for API calls or routine O&M.
// This example shows how to store the AccessKey ID and AccessKey secret in environment variables. For information about how to configure environment variables, see https://help.aliyun.com/document_detail/311677.html
$credential = new Credential([]);
$config = new Config([
'credential' => $credential,
'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
]);
// To hard-code your AccessKey ID and AccessKey secret, use the following code. We strongly recommend that you do not hard-code your AccessKey information in your project code. This prevents AccessKey leaks and protects your resources.
// $config->accessKeyId = '<yourAccessKeyId>';
// $config->accessKeySecret = '<yourAccessKeySecret>';
$client = new ICE($config);
$request = new CreateUploadMediaRequest();
$request->fileInfo = "{\"Type\":\"video\",\"Name\":\"test\",\"Size\":123,\"Ext\":\"mp4\"}";
$request->mediaMetaData = "{\"Title\":\"UploadTest\",\"Description\":\"UploadTest\",\"BusinessType\":\"general\"}";
$request->uploadTargetConfig = "fullText = 'China'";
$response = $client->createUploadMedia($request);
echo json_encode($response->body);
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
}
Related API operations
CreateUploadMedia - Obtain an upload URL and credentials for a media asset
Is this page helpful?