You need to enable JavaScript to run this app.
导航
空间管理
最近更新时间:2024.09.29 17:41:41首次发布时间:2022.06.21 14:21:21

本文为您提供服务端 Java SDK 空间管理模块的接口调用示例。

前提条件

调用接口前,请先完成 SDK 的安装初始化

调用示例

创建空间

接口请求参数和返回参数说明详见 CreateSpace

package com.volcengine.example.vod.space;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodCreateSpaceDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodCreateSpaceRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodCreateSpaceRequest.newBuilder();
                        reqBuilder.setSpaceName("your SpaceName");
                        reqBuilder.setProjectName("your ProjectName");
                        reqBuilder.setDescription("your Description");
                        reqBuilder.setRegion("your Region");
                        reqBuilder.setUserName("your UserName");
                        
            com.volcengine.service.vod.model.response.VodCreateSpaceResponse resp = vodService.createSpace(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

获取空间列表

接口请求参数和返回参数说明详见 ListSpace

package com.volcengine.example.vod.space;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodListSpaceDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodListSpaceRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodListSpaceRequest.newBuilder();
                        reqBuilder.setOffset(0);
                        reqBuilder.setLimit(0);
                        
            com.volcengine.service.vod.model.response.VodListSpaceResponse resp = vodService.listSpace(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

获取空间详细信息

接口请求参数和返回参数说明详见 GetSpaceDetail

package com.volcengine.example.vod.space;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodGetSpaceDetailDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodGetSpaceDetailRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodGetSpaceDetailRequest.newBuilder();
                        reqBuilder.setSpaceName("your SpaceName");
                        
            com.volcengine.service.vod.model.response.VodGetSpaceDetailResponse resp = vodService.getSpaceDetail(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

更新空间信息

接口请求参数和返回参数说明详见 UpdateSpace

package com.volcengine.example.vod.space;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodUpdateSpaceDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodUpdateSpaceRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodUpdateSpaceRequest.newBuilder();
                        reqBuilder.setSpaceName("your SpaceName");
                        reqBuilder.setSourceProjectName("your SourceProjectName");
                        reqBuilder.setTargetProjectName("your TargetProjectName");
                        reqBuilder.setDescription("your Description");
                        
            com.volcengine.service.vod.model.response.VodUpdateSpaceResponse resp = vodService.updateSpace(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

更新空间上传配置

接口请求参数和返回参数说明详见 UpdateSpaceUploadConfig

package com.volcengine.example.vod.space;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodUpdateSpaceUploadConfigDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodUpdateSpaceUploadConfigRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodUpdateSpaceUploadConfigRequest.newBuilder();
                        reqBuilder.setSpaceName("your SpaceName");
                        reqBuilder.setConfigKey("your ConfigKey");
                        reqBuilder.setConfigValue("your ConfigValue");
                        
            com.volcengine.service.vod.model.response.VodUpdateSpaceUploadConfigResponse resp = vodService.updateSpaceUploadConfig(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}