Obtain an upload URL and credentials for a media asset
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.
Usage notes
To configure environment variables, see Configure environment variables in Linux, macOS, and Windows.
Sample code
To debug this operation online, visit Alibaba Cloud OpenAPI Developer Portal.
package com.aliyun.ice.sample;
import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;
public class Sample {
public static void main(String[] args) throws Exception {
// The AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
// In this example, the AccessKey ID and AccessKey secret are obtained from environment variables. For more information about how to configure them, see https://help.aliyun.com/document_detail/378657.html
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config();
config.setCredential(credentialClient);
// To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// config.accessKeyId = <yourAccessKeyId>;
// config.accessKeySecret = <yourAccessKeySecret>;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
Client client = new Client(config);
CreateUploadMediaRequest request = new CreateUploadMediaRequest()
.setFileInfo("{\"Type\":\"video\",\"Name\":\"test\",\"Size\":123,\"Ext\":\"mp4\"}")
.setMediaMetaData("{\"Title\":\"UploadTest\",\"Description\":\"UploadTest\",\"BusinessType\":\"general\"}")
.setUploadTargetConfig("{\"StorageType\":\"oss\",\"StorageLocation\":\"out-****.oss-cn-shanghai.aliyuncs.com\"}");
CreateUploadMediaResponse response = client.createUploadMedia(request);
System.out.println("CreateUploadMedia, mediaId: " + response.getBody().getMediaId());
}
}Related API operations
CreateUploadMedia - Obtain an upload URL and credentials for a media asset
Is this page helpful?