CDNetworks Documentation Cloud VoD API Reference(Old) Example: Include Authentication in Request

Example: Include Authentication in Request

Last update:2023-02-08 10:00:19

Contents

Example 1: Get Video List in Cloud VoD through Authentication V3 (Java)

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"));
    }

}

Example 2: Get Upload Token and then Upload in Postman

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:

  1. Get an Upload Token.
  2. Upload the video.

Get Upload Token

Firstly import the script to your Postman. Change the secretKey and accessKey to your own AccessKey Secret and AccessKey ID.
AquaNPlayer(Windows & MAC) 업데이트 안내
Change the orginFileName to the name of your own video that you want to upload. Then send a request.
AquaNPlayer(Windows & MAC) 업데이트 안내
Copy and save uploadUrl and uploadToken for a further use in video upload.
AquaNPlayer(Windows & MAC) 업데이트 안내

Upload the Video

As having the upload token and URL, now you can upload your video. Go to API Normal Upload, please follow the steps below:

  1. Change the domain to the uploadUrl you get from Get Upload Token API.
  2. Select the file that you want to upload.
  3. Fill in the token you get from Get Upload Token API.
    AquaNPlayer(Windows & MAC) 업데이트 안내
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!