This topic describes how to use the upload SDK for PHP to upload media files to ApsaraVideo VOD for storage.
Upload process
The upload SDK for Java follows the general upload process of ApsaraVideo VOD SDKs. For more information, see Upload process. The following content describes the process of using the upload SDK for PHP:
Complete the configurations as described in the Prerequisites section.
Integrate the upload SDK for PHP. For more information, see Integrate the upload SDK for PHP.
Configure upload information to implement the upload logic.
For more information about how to upload audio or video files, see Scenario 1: Upload audio and video files.
For more information about how to upload images, see Scenario 2: Upload images.
For more information about how to upload auxiliary media assets, see Scenario 3: Upload auxiliary media assets.
The default endpoint of the upload SDK for PHP is
cn-shanghai
. If you want to upload media files to a region other than the China (Shanghai) region, you can configureAliyunVodUploader
to specify a region when you initialize the SDK. For more information about the supported endpoints, see Endpoints.The following sample code provides an example on how to upload media files to the
China (Beijing)
region:$apiRegionId = 'cn-beijing'; // Upload media files to the China (Beijing) region. $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret, $apiRegionId);
Prerequisites
ApsaraVideo VOD is activated. For more information, see Activate ApsaraVideo VOD.
The system settings required for the upload, including the storage path in the specified region and the callback settings, are configured. For more information, see Manage storage buckets and Configure callbacks.
A RAM user is created and used to access ApsaraVideo VOD. To prevent security risks caused by the leakage of the AccessKey pair of your Alibaba Cloud account, we recommend that you create a RAM user and grant the RAM user the permissions required to access ApsaraVideo VOD. Then, you can use the AccessKey pair of the RAM user to access ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user.
Optional. A role is created for the RAM user and the role is granted the permissions required to access ApsaraVideo VOD if you want to access ApsaraVideo VOD by using Security Token Service (STS). For more information, see Use STS to upload videos.
NoteFor more information about the scenarios in which STS can be used, see Comparison between credentials and STS.
Integrate the upload SDK for PHP
Download the package VodUploadSDK-PHP_1.0.3.zip that contains the upload SDK for PHP and sample code. For more information, see SDK overview and download.
NoteIn this example, the upload SDK for PHP V1.0.3 is used. You can use other versions based on your business requirements.
For more information about the directories after decompression, see Directories.
Decompress the VodUploadSDK-PHP_1.0.3.zip file and copy the voduploadsdk folder in the VodUploadSDK-PHP_1.0.3 directory to your project.
Update the upload SDK for PHP
If new operations or new features of existing operations are unavailable in the current SDK, update the SDK to the latest version. For more information, see Upload SDK.
You can obtain the version number and release date of the current SDK in the first line of the ChangeLog.txt file in the voduploadsdk directory.
Directories
/VodUploadSDK-PHP_1.0.3.zip/VodUploadSDK-PHP_1.0.3/voduploadsdk/uploader
UploadVideoRequest.php
Directory
Description
UploadVideoRequest
The request class for video upload. For more information about the parameters, see CreateUploadVideo.
UploadImageRequest.php
Directory
Description
UploadImageRequest
The request class for image upload. For more information about the parameters, see CreateUploadImage.
UploadAttachedMediaRequest.php
Directory
Description
UploadAttachedMediaRequest
The request class for the upload of auxiliary media assets. For more information about the parameters, see CreateUploadAttachedMedia.
AliyunVodUploader.php
Directory
Description
__construct
The constructor used to set the AccessKey pair, access region, and access domain name of ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user and Region IDs of ApsaraVideo VOD.
uploadLocalVideo
The API operation that is used to upload local videos.
uploadWebVideo
The API operation that is used to upload online videos.
uploadLocalImage
The API operation used to upload local images.
uploadWebImage
The API operation used to upload online images.
uploadLocalAttachedMedia
The API operation used to upload local auxiliary media assets.
uploadWebAttachedMedia
The API operation used to upload online auxiliary media assets.
uploadLocalM3u8
The API operation used to upload local M3U8 videos.
uploadWebM3u8
The API operation used to upload online M3U8 videos.
parseM3u8File
The API operation used to parse the M3U8 index file to obtain the URLs of part files.
setEcsRegionId
The API operation used to specify the region of the Elastic Compute Service (ECS) instance on which the upload script is to be deployed. If the region of the ECS instance is the same as the storage region in ApsaraVideo VOD, the file is automatically uploaded over the internal network.
setEnableSSL
The API operation used to specify whether to send requests over HTTPS. By default, HTTPS is disabled to prevent failures when related extensions are not installed or a configuration exception occurs.
uploadProgressCallback
The API operation used to configure the callback for the upload progress. This results can be overridden.
AliyunVodUtils.php
Directory
Description
AliyunVodUtils
The utility class that provides static functions for truncating strings and obtaining extensions and file names.
AliyunVodLog
The log class that provides the logging feature. You can configure the logSwitch parameter to enable or disable logging.
AliyunVodDownloader
The class that is used to download online files.
AliyunVodReportUpload
The class that is used to report the upload progress.
AliyunVodError
The class that is used to define error codes.
/VodUploadSDK-PHP_1.0.3.zip/VodUploadSDK-PHP_1.0.3/voduploadsdk
aliyun-php-sdk-core: the base class on which the upload SDK depends. This package encapsulates Alibaba Cloud API signatures and HTTP requests.
aliyun-php-sdk-vod: the ApsaraVideo VOD SDK. This package encapsulates API requests of ApsaraVideo VOD.
aliyun-php-sdk-oss: the Object Storage Service (OSS) class on which the upload SDK depends. This package encapsulates operations such as OSS uploads.
/VodUploadSDK-PHP_1.0.3.zip/VodUploadSDK-PHP_1.0.3/samples
uploadVideo.php: sample code for video upload.
uploadImage.php: sample code for image upload.
uploadAttachedMedia.php: sample code for the upload of auxiliary media assets.
Scenario 1: Upload audio and video files
Regular audio and video files
The upload SDK for PHP supports the following types of audio and video files:
Use multipart upload to upload a local file. You can upload a file of up to 48.8 TB in size. Resumable upload is not supported. For more information, see the testUploadLocalVideo function in the sample code.
Use the file URL to upload an online file. You can upload a file of up to 48.8 TB in size. Before you upload online files, you must download the files to a local disk. Make sure that the local disk has sufficient space. For more information, see the testUploadWebVideo function in the sample code.
M3U8 files
Sample code:
Scenario 2: Upload images
Scenario 3: Upload auxiliary media assets
Sample code: