通过阅读本文,您可以了解通过服务端SDK调用OpenAPI获取媒资上传地址和凭证的示例代码。
示例代码
您可以通过阿里云OpenAPI开发者门户在线调试。
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 Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config();
config.accessKeyId = accessKeyId;
config.accessKeySecret = accessKeySecret;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
config.regionId = "cn-shanghai";
return new Client(config);
}
public static void main() throws Exception {
Client client = Sample.createClient("ACCESS_KEY_ID", "ACCESS_KEY_SECRET");
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());
}
}