This topic describes how to use ApsaraVideo VOD SDK for Java to call API operations as an example.
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 operation by using one of the following identities: Alibaba Cloud account, Resource Access Management (RAM) role, and RAM user. For more information about the differences between the identities, see Identity, credential, and authorization.
In this topic, the RAM user is used as an example.
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
On the Users page of the RAM console, find the RAM user that you want to manage and click Add Permissions in the Actions column.
In the panel that appears, enter
VOD
in the search box and select the AliyunVODUploadAuth policy.NoteAliyunVODFullAccess: 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.
Click Grant permissions.
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.
Set environment variables
This section describes how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. For more information, see Configure environment variables in Linux, macOS, and Windows.
Download the sample code
Open the CreateUploadVideo page.
On the left side of the page, specify the parameters on the Parameters tab.
Specify FileName. Example: product-introduction.mp4.
Specify Title. Example: Product introduction.
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.
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
}