All Products
Search
Document Center

Media upload

Last Updated: Jul 11, 2019

This topic describes how to use the PHP server SDK to call server operations, for example, to obtain the upload URL and credential and register media asset information. To upload complete media files, you can use the client upload SDK together with the upload URL and credential or directly use the PHP server upload SDK.

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Obtain the video upload URL and credential

For more information about the request and response parameters, see CreateUploadVideo.

/**
 * Method for obtaining the video upload URL and credential
 * @param client The client that sends a request.
 * @return CreateUploadVideoResponse The response to the request for obtaining the video upload URL and credential.
 */
function createUploadVideo($client) {
    $request = new vod\CreateUploadVideoRequest();
    $request->setTitle("Sample Title");        
    $request->setFileName("videoFile.mov"); 
    $request->setDescription("Video Description");
    $request->setCoverURL("http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"); 
    $request->setTags("tag1,tag2");

    $request->setAcceptFormat('JSON');
    return $client->getAcsResponse($request); 
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $uploadInfo = createUploadVideo($client);
    var_dump($uploadInfo);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Refresh the video upload credential

For more information about the request and response parameters, see RefreshUploadVideo.

/**
 * Method for refreshing the video upload credential
 * @param client The client that sends a request.
 * @return RefreshUploadVideoResponse The response to the request for refreshing the video upload credential.
 */
function refreshUploadVideo($client, $videoId) {
    $request = new vod\RefreshUploadVideoRequest();
    $request->setVideoId($videoId); 
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $refreshInfo = refreshUploadVideo($client, 'videoId');
    var_dump($refreshInfo);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Obtain the image upload URL and credential

For more information about the request and response parameters, see CreateUploadImage.

/**
 * Method for obtaining the image upload URL and credential
 * @param client The client that sends a request.
 * @return CreateUploadImageResponse The response to the request for obtaining the image upload URL and credential.
 */
function createUploadImage($client, $imageType, $imageExt) {
    $request = new vod\CreateUploadImageRequest();
    $request->setImageType($imageType); 
    $request->setImageExt($imageExt); 
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $imageInfo = createUploadImage($client, 'cover', 'jpg');
    var_dump($imageInfo);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Obtain the upload URL and credential for an attached media asset

For more information about the request and response parameters, see CreateUploadAttachedMedia.

/**
 * Method for obtaining the upload URL and credential for an attached media asset (such as a watermark or subtitle file)
 * @param client The client that sends a request.
 * @return CreateUploadAttachedMediaResponse The response to the request for obtaining the upload URL and credential for an attached media asset.
 */
function createUploadAttachedMedia($client) {
    $request = new vod\CreateUploadAttachedMediaRequest();
    $request->setBusinessType("watermark");
    $request->setMediaExt("gif");
    $request->setTitle("this is a sample");

    return $client->getAcsResponse($request);
}


try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $result = createUploadAttachedMedia($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Upload multiple videos based on mezzanine file URLs

For more information about the request and response parameters, see UploadMediaByURL.

/**
 * Method for uploading multiple videos based on mezzanine file URLs
 * @param client The client that sends a request.
 * @return UploadMediaByURLResponse The response to the request for uploading multiple videos based on mezzanine file URLs.
 */
function uploadMediaByURL($client) {
    $request = new vod\UploadMediaByURLRequest();
    $url = "http://test.xxx.com/xxxx.mp4";
    $request->setUploadURLs($url); 

    $uploadMetadataList = array();
    $uploadMetadata = array();
    $uploadMetadata["SourceUrl"] = $url;
    $uploadMetadata["Title"] = "upload by url sample";
    $uploadMetadataList[] = $uploadMetadata;
    $request->setUploadMetadatas(json_encode($uploadMetadataList)); 

    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $result = uploadMediaByURL($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Register media asset information

For more information about the request and response parameters, see RegisterMedia.

/**
 * Method for registering media asset information
 * @param client The client that sends a request.
 * @return RegisterMediaResponse The response to the request for registering media asset information.
 */
function registerMedia($client) {
    $request = new vod\RegisterMediaRequest();

    $metaDataArray= array();
    $metaData= array();
    $metaData["Title"] = "registerMedia by url sample";
    $metaData["FileURL"] = "https://xxxxxx.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4";
    $metaDataArray[] = $metaData;
    $request->setRegisterMetadatas(json_encode($metaDataArray)); 

    return $client->getAcsResponse($request);
}


try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $result = registerMedia($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Obtain the information about upload based on mezzanine file URLs

For more information about the request and response parameters, see GetURLUploadInfos.

/**
 * Method for obtaining the information about upload based on mezzanine file URLs
 * @param client The client that sends a request.
 * @return GetURLUploadInfosResponse The response to the request for obtaining the information about upload based on mezzanine file URLs.
 */
function getURLUploadInfos($client) {
    $request = new vod\GetURLUploadInfosRequest();

    // Specifies a list of mezzanine file URLs.
    $urls = array();
    $urls[] = "http://xxx.cn-shanghai.aliyuncs.com/sample1.mp4";
    $urls[] = "http://xxx.cn-shanghai.aliyuncs.com/sample2.mp4";

    // Encodes mezzanine file URLs.
    $uploadURLs = array();
    foreach ($urls as $url) {
       $uploadURLs[] = urlencode($url); 
    }

    // Specifies a list of mezzanine file URLs. Separate multiple URLs with a comma (,).
    $request->setUploadURLs(implode(",", $uploadURLs)); 

    // Specifies the IDs of upload jobs, alternatively.
    //$request->setJobIds("jobId1xxxxxx,jobId2xxxxxx") 

    return $client->getAcsResponse($request);
}


try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 

    $result = getURLUploadInfos($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}