Last update:2023-02-08 10:00:19
Before using the code, you should import until.jar to your project.
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"));
}
}
Here we give an example to show how upload a video by sending requests in Postman. You can download the Postman Script and import into your Postman tool to easily send requests and upload your video to Cloud VoD.
There are two steps:
Firstly import the script to your Postman. Change the secretKey and accessKey to your own AccessKey Secret and AccessKey ID.
Change the orginFileName to the name of your own video that you want to upload. Then send a request.
Copy and save uploadUrl and uploadToken for a further use in video upload.
As having the upload token and URL, now you can upload your video. Go to API Normal Upload, please follow the steps below: