更新时间:2023-02-08 10:00:19
在使用代码之前,您应该将until.jar导入到您的项目中。
import com.cnc.cloudv.util.auth.ApiAuthUtil;
import com.cnc.cloudv.util.httpclient.CloudvHttpResponse;
import java.util.HashMap;
import java.util.Map;
public class TestAuthUtil {
private final static String ACCESS_KEY = "Your AccessKey";
private final static String SECRET_KEY = "Your AccessKey Secret";
// API_HOST is Cloud VoD API domain
private final static String API_HOST = "api.cloudv.haplat.net";
public static void main(String[] args) throws Exception {
Map<String, String> customHeaderMap = new HashMap<String, String>(2);
// below is a customized header
customHeaderMap.put("from", "test-authentification-sdk");
// URI of the request
String requestURI = "/vod/videoManage/getVideoList";
// POST request example
String body = "{\"videoName\": \"test\",\"pageIndex\":\"2\",\"pageSize\":\"5\",\"format\": \"json\"}";
CloudvHttpResponse cloudvHttpResponse = ApiAuthUtil.callPostJsonBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, body);
log(cloudvHttpResponse);
// GET request example
String canonicalQueryString = "videoName=" + java.net.URLEncoder.encode("test", "utf-8") + "&pageIndex=2&pageSize=5&format=json";
cloudvHttpResponse = ApiAuthUtil.callGetRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, canonicalQueryString);
log(cloudvHttpResponse);
// Form-Urlencoded POST request example
body = "videoName=" + java.net.URLEncoder.encode("test", "utf-8") + "&pageIndex=2&pageSize=5&format=json";
cloudvHttpResponse = ApiAuthUtil.callPostFormUrlencodedBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, body);
log(cloudvHttpResponse);
// Map POST request example
Map<String, String> map = new HashMap<String, String>();
map.put("videoName", "test");
map.put("pageIndex", "2");
map.put("pageSize", "5");
map.put("format", "json");
cloudvHttpResponse = ApiAuthUtil.callPostFormUrlencodedBodyRequest(API_HOST, ACCESS_KEY, SECRET_KEY, requestURI, customHeaderMap, map);
log(cloudvHttpResponse);
System.out.print("Request ends");
}
public static void log(CloudvHttpResponse cloudvHttpResponse) throws Exception {
// Print out the X-WS-RequestId for a further troubleshooting
System.out.println("Response:" + cloudvHttpResponse + " , requestId = " + cloudvHttpResponse.getHeaders().get("X-WS-RequestId"));
}
}
下面我们举例说明如何在 Postman 中通过发送请求来上传视频。您可以下载Postman 脚本并导入到您的 Postman 工具中,以轻松发送请求并将您的视频上传到 Cloud VoD。
有两个步骤:
首先将脚本导入您的 Postman。将secretKey和accessKey改成自己的AccessKey Secret和AccessKey ID。
将 orginFileName 更改为您自己要上传的视频的名称。然后发送请求。
复制并保存 uploadUrl 和 uploadToken 以便在视频上传中进一步使用。
有了上传令牌和 URL,现在您可以上传视频了。进入API正常上传,请按照以下步骤操作: