全部產品
Search
文件中心

Data Online Migration:資料地址

更新時間:Dec 11, 2025

本文介紹如何使用SDK調用資料地址相關的方法。

建立資料地址

以下範例程式碼用於建立OSS類型的資料地址。

重要
  • 建立OSS類型的資料地址前需要先進行角色配置, 並擷取到角色 (rolename)。

  • 是否需要關聯代理需要根據具體情況而定,請參見文檔 使用代理遷移-概述。建立其它類型資料地址關聯代理的方法與該樣本相同。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** 填寫主帳號ID。*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// 填寫資料位址名稱。
		String addressName = "exampleaddress";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// 這裡以北京地區為例。
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
                        config.setProtocol("http");
			Client client = new Client(config);
			AddressDetail detail = new AddressDetail();
			detail.addressType = "oss";
			// 以下參數請根據實際值填寫。
			detail.bucket = "examplebucket";
			detail.prefix = "***/";
			detail.regionId = "oss-cn-beijing";
			detail.role = "rolename_xxxxx";
			// 代理列表。無需關聯代理則不用指定。
			detail.agentList = "agent1,agent2,agent3";
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

以下範例程式碼用於建立Oss Inventory類型的資料地址。

重要

建立Oss Inventory類型的資料地址前需要先進行角色配置,並擷取到角色和清單角色(rolename 和 invrolename)。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "ossinv";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         detail.regionId = "oss-cn-beijing";
         detail.role = "rolename_*******";
         // 以下參數為清單相關資訊。
         detail.invLocation = "oss";
         detail.invAccessId = "***";
         detail.invAccessSecret = "******";
         detail.invBucket = "exampleinvbucket";
         detail.invRegionId = "oss-cn-beijing";
         detail.invRole = "invrolename_*******";
         detail.invPath = "dir/manifest.json";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

以下範例程式碼用於建立通用清單 Inventory 類型的資料地址。

重要

建立 Inventory 類型的資料地址前需要先進行角色配置,並擷取到角色和清單角色(rolename 和 invrolename)。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "inv";
         // 當 addressType 為 inv時,可選值為oss、s3、cos、obs、tos、qiniu、gcp、azure、ks3、bos、us3、uss。
         detail.dataType = "oss";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         detail.regionId = "oss-cn-beijing";
         detail.role = "rolename_*******";
         // 以下參數為清單相關資訊。
         detail.invLocation = "oss";
         detail.invAccessId = "***";
         detail.invAccessSecret = "******";
         detail.invBucket = "exampleinvbucket";
         detail.invRegionId = "oss-cn-beijing";
         detail.invRole = "invrolename_*******";
         detail.invPath = "dir/manifest.json";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

以下範例程式碼用於建立第三方源類型的資料地址。

s3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "s3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "s3.ap-southeast-1.amazonaws.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

cos

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "cos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "cos.ap-nanjing.myqcloud.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

obs

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "obs";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "obs.cn-north-1.myhuaweicloud.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

tos

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "tos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "tos-s3-cn-beijing.volces.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

qiniu

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "qiniu";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // 網域名稱說明請參見https://developer.qiniu.com/kodo/8527/kodo-domain-name-management
         detail.domain = "http://xxxx.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

gcp

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "gcp";
         detail.accessId = "***";
         detail.accessSecret = "******";
         // domain請跟根據實際值填寫。
         detail.domain = "Cloud Storage URI";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

azure

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "azure";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "https://<儲存帳號>.blob.core.windows.net";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

ks3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "ks3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "ks3-cn-beijing.ksyuncs.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

bos

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "bos";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "bj.bcebos.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

ucloud s3

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "us3";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "cn-bj.ufileos.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

youpai

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         AddressDetail detail = new AddressDetail();
         // 以下參數為待遷移資料相關資訊,請根據實際值填寫。
         detail.addressType = "uss";
         detail.accessId = "***";
         detail.accessSecret = "******";
         detail.domain = "s3.api.upyun.com";
         detail.bucket = "examplebucket";
         detail.prefix = "***/";
         CreateAddressRequest request = new CreateAddressRequest();
         CreateAddressInfo info = new CreateAddressInfo();
         info.name = addressName;
         info.setAddressDetail(detail);
         request.setImportAddress(info);
         client.createAddress(userId, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

以下範例程式碼用於建立HTTP類型的資料地址。

重要

建立HTTP類型的資料地址前需要先進行角色配置,並擷取到清單角色 (invrolename)。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** 填寫主帳號ID。*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// 填寫資料位址名稱。
		String addressName = "exampleaddress";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// 這裡以北京地區為例。
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
                        config.setProtocol("http");
			Client client = new Client(config);
			AddressDetail detail = new AddressDetail();
			// 以下參數為待遷移資料相關資訊,請根據實際值填寫。
			detail.addressType = "http";
			detail.invLocation = "oss";
			detail.invBucket = "exampleinvbucket";
			detail.invDomain = "oss-cn-beijing.aliyuncs.com";
			detail.invRole = "invrolename_*******";
			detail.invPath = "dir/manifest.json";
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

以下範例程式碼用於建立LocalFS類型的資料地址,LocalFS類型資料地址必須關聯代理。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.AddressDetail;
import com.aliyun.hcs_mgw20240626.models.CreateAddressInfo;
import com.aliyun.hcs_mgw20240626.models.CreateAddressRequest;

public class Demo {
	/** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** 填寫主帳號ID。*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// 填寫資料位址名稱。
		String addressName = "exampleaddress";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// 這裡以北京地區為例。
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
                        config.setProtocol("http");
			Client client = new Client(config);
			AddressDetail detail = new AddressDetail();
			// 以下參數為待遷移資料相關資訊,請根據實際值填寫。
			detail.addressType = "local";
			detail.prefix = "/***/";
			// 代理列表
			detail.agentList = "agent1,agent2,agent3"
			CreateAddressRequest request = new CreateAddressRequest();
			CreateAddressInfo info = new CreateAddressInfo();
			info.name = addressName;
			info.setAddressDetail(detail);
			request.setImportAddress(info);
			client.createAddress(userId, request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

擷取資料地址詳情

以下範例程式碼用於擷取資料地址詳情資訊。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.GetAddressResponse;
import com.google.gson.Gson;

public class Demo {
	/** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
	static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
	static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
	/** 填寫主帳號ID。*/
	static String userId = "11470***876***55";

	public static void main(String[] args) {
		// 填寫資料位址名稱。
		String addressName = "exampleaddress";
		try {
			com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
			// 這裡以北京地區為例。
			config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
			config.setAccessKeyId(accessKeyId);
			config.setAccessKeySecret(accessKeySecret);
			// 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
                        config.setProtocol("http");
			Client client = new Client(config);
			GetAddressResponse resp = client.getAddress(userId, addressName);
			System.out.println(new Gson().toJson(resp.getBody().getImportAddress()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

正常返回樣本

{
  "ImportAddress": {
    "Owner": "test_owner",
    "Name": "test_name",
    "AddressDetail": {
      "AddressType": "ossinv",
      "Bucket": "test_bucket",
      "Domain": "test_domain",
      "Prefix": "test_prefix",
      "AccessId": "test_access_id",
      "AccessSecret": "test_secret_key",
      "Role": "test_role",
      "InvDomain": "test_inv_domain",
      "InvBucket": "test_inv_bucket",
      "InvAccessId": "test_inv_access_id",
      "InvAccessSecret": "test_inv_secret_key",
      "InvPath": "manifest.json",
      "InvRole": "test_inv_role",
      "InvLocation": "oss",
      "AgentList": "agent1,agent2",
      "RegionId": "test_region_id",
      "InvRegionId": "test_inv_region_id"
    },
    "CreateTime": "2024-05-01T12:00:00.000Z",
    "ModifyTime": "2024-05-01T12:00:00.000Z",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "Version": "test_id",
    "Tags": "K1:V1,K2:V2",
    "Status": "available",
    "VerifyResult": {
      "HttpCode": "400",
      "ErrorCode": "InvalidArgument",
      "ErrorMsg": "Invalid argument."
    }
  }
}

校正資料地址

以下範例程式碼用於驗證指定的資料地址是否可用。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.VerifyAddressResponse;
import com.google.gson.Gson;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         VerifyAddressResponse resp = client.verifyAddress(userId, addressName);
         // 僅當status 欄位值為 available 時表示資料地址有效,其它任何值均表示無效。
         System.out.println(new Gson().toJson(resp.getBody().verifyAddressResponse.status));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

正常返回地址可用樣本

{
  "VerifyAddressResponse": {
    "Status": "available",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "",
    "ErrorMessage": ""
  }
}

正常返回地址不可用樣本

{
  "VerifyAddressResponse": {
    "Status": "unavailable",
    "VerifyTime": "2024-05-01T12:00:00.000Z",
    "ErrorCode": "400",
    "ErrorMessage": "Invalid argument."
  }
}

列舉資料地址

以下範例程式碼用於列舉帳號下所有資料地址資訊。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.ListAddressRequest;
import com.aliyun.hcs_mgw20240626.models.ListAddressResponse;
import com.google.gson.Gson;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         ListAddressRequest request = new ListAddressRequest();
         // 根據實際填寫marker,count。
         String marker = "";
         int count = 1;
         request.setMarker(marker);
         request.setCount(count);
         ListAddressResponse resp = client.listAddress(userId, request);
         System.out.println(new Gson().toJson(resp.getBody().getImportAddressList()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

正常返回樣本

{
  "ImportAddressList": {
    "Truncated": true,
    "NextMarker": "test_marker",
    "ImportAddress": [
      {
        "Owner": "test_owner",
        "Name": "test_name",
        "AddressDetail": {
          "AddressType": "ossinv",
          "Bucket": "test_bucket",
          "Domain": "test_domain",
          "Prefix": "test_prefix",
          "AccessId": "test_access_id",
          "AccessSecret": "test_secret_key",
          "Role": "test_role",
          "InvDomain": "test_inv_domain",
          "InvBucket": "test_inv_bucket",
          "InvAccessId": "test_inv_access_id",
          "InvAccessSecret": "test_inv_secret_key",
          "InvPath": "manifest.json",
          "InvRole": "test_inv_role",
          "InvLocation": "oss",
          "AgentList": "agent1,agent2",
          "RegionId": "test_region_id",
          "InvRegionId": "test_inv_region_id"
        },
        "CreateTime": "2024-05-01T12:00:00.000Z",
        "ModifyTime": "2024-05-01T12:00:00.000Z",
        "VerifyTime": "2024-05-01T12:00:00.000Z",
        "Version": "test_id",
        "Tags": "K1:V1,K2:V2",
        "Status": "available",
        "VerifyResult": {
          "HttpCode": "400",
          "ErrorCode": "InvalidArgument",
          "ErrorMsg": "Invalid argument."
        }
      }
    ]
  }
}

更新資料地址

以下範例程式碼用於代理需要擴容或縮容的情境,更新指定資料地址關聯的代理。

重要

至少需要填寫一個代理名稱,並且代理的通道不允許更改,否則更新失敗。

package sample;

import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      // 填寫代理名稱列表,以,分隔, 不可為空白。
      String agentList = "exampleagent1,exampleagent2,exampleagent3...";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         UpdateAddressRequest request = new UpdateAddressRequest();
         UpdateAddressInfo info = new UpdateAddressInfo();
         info.setAgentList(agentList);
         request.setImportAddress(info);
         client.updateAddress(userId, addressName, request);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

刪除資料地址

以下範例程式碼用於刪除指定資料地址。

package sample;

import com.aliyun.hcs_mgw20240626.Client;

public class Demo {
   /** 強烈建議不要把AccessKey ID和AccessKey Secret儲存到工程代碼裡,否則可能導致AccessKey泄露,威脅您帳號下所有資源的安全。*/
   static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
   static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
   /** 填寫主帳號ID。*/
   static String userId = "11470***876***55";

   public static void main(String[] args) {
      // 填寫資料位址名稱。
      String addressName = "exampleaddress";
      try {
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
         // 這裡以北京地區為例。
         config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
         config.setAccessKeyId(accessKeyId);
         config.setAccessKeySecret(accessKeySecret);
         // 支援 HTTPS、HTTP, 未指定時預設採用 HTTPs。
         config.setProtocol("http");
         Client client = new Client(config);
         client.deleteAddress(userId, addressName);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

後續步驟

資料地址建立完成後,您可以選擇繼續執行建立任務的操作,詳細資料請參見任務