All Products
Search
Document Center

ApsaraVideo VOD:Usage example of the ApsaraVideo VOD API

Last Updated:Jan 18, 2024

This topic describes how to use the ApsaraVideo VOD API to obtain the upload URL and credential for audio and video files.

View the API documentation

Before you upload files, we recommend that you read the documentation of the CreateUploadVideo operation to learn about the parameters and permissions required to call the operation. For more information, see List of operations by function.

Create a RAM user and grant permissions to the RAM user

Identity

You can call the CreateUploadVideo operation by using an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role. For more information about the differences between different identities, see Identity, credential, and authorization.

In this topic, the RAM user is used as an example.

  1. Log on to the RAM console, create a RAM user, and then grant the RAM user permissions to call API operations. For more information, see Create a RAM user.

Authorization

  1. On the Users page, find the RAM user whose permissions you want to manage and click Add Permissions in the Actions column.

  2. In the panel that appears, enter VOD in the search box and select the AliyunVODUploadAuth policy.

    Note

    AliyunVODFullAccess: full access to ApsaraVideo VOD resources.

    AliyunVODReadOnlyAccess: read-only permissions on ApsaraVideo VOD resources.

    AliyunVODPlayAuth: permissions to play media files in ApsaraVideo VOD.

    AliyunVODUploadAuth: permissions to upload files to ApsaraVideo VOD.

    For more information about how to create a custom policy, see RAM authorization.

  3. Click OK.

Call the API

In this topic, ApsaraVideo VOD SDK for Java is used to call API operations. For more information about how to use SDKs for other programming languages, visit OpenAPI Explorer. You can use other methods to call API operations based on your business requirements. For more information, see Overview.

Configure environment variables

This section describes how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables in your operating system.

  • If you use the Linux or macOS operating system, replace <access_key_id> and <access_key_secret> in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands on your device. For more information about how to create an AccessKey pair, see Create an AccessKey pair.

    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • If you use a Windows operating system, create a file to add the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables, specify your AccessKey ID and AccessKey secret by using the environment variables, and then restart the system.

Download the sample code

  1. Open the CreateUploadVideo page.

  2. On the left side of the page, specify the parameters on the Parameters tab.

    1. Specify FileName. Example: product-introduction.mp4.

    2. Specify Title. Example: Product introduction.

  3. On the SDK Sample Code tab, select V2.0 from the SDK Version drop-down list, click Java in the Languages field, and then click Download Project to download the sample code package.

  4. Decompress the sample code package on your local device and open the alibabacloud_sample directory.

Load the project

Load the project by using IntelliJ IDEA. After the dependencies are loaded, open the Sample.java file in the src/main/java/com/aliyun/sample/ directory. Add code to display the return values based on the comments in the code.

Run the project

In the upper-right corner, click Run to view the output logs. Sample response:

{
  "headers": {
    "access-control-allow-origin": "*",
    "date": "Wed, 12 Jul 2023 01:01:15 GMT",
    "keep-alive": "timeout=25",
    "transfer-encoding": "chunked",
    "vary": "Accept-Encoding",
    "x-acs-request-id": "DB669C38-72B2-539C-87E2-76D1E3AAC3E2",
    "connection": "keep-alive",
    "content-type": "application/json;charset=utf-8",
    "access-control-expose-headers": "*",
    "x-acs-trace-id": "a40b3573c2e372121a05767e5bfe****"
  },
  "body": {
    "UploadAddress": "***",
    "VideoId": "***",
    "RequestId": "DB669C38-72B2-539C-87E2-76D1E3AAC3E2",
    "UploadAuth": "***"
  },
  "statusCode": 200
}