use of com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class GetObjectURLDemo method getObjectUrlWithEndpoint.
public static void getObjectUrlWithEndpoint() {
// getObjectUrl 不需要验证身份信息
COSCredentials cred = new AnonymousCOSCredentials();
// 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 设置生成的 url 的协议名
clientConfig.setHttpProtocol(HttpProtocol.https);
// 设置自定义的域名
UserSpecifiedEndpointBuilder endpointBuilder = new UserSpecifiedEndpointBuilder("test.endpoint.com", "service.cos.myqcloud.com");
clientConfig.setEndpointBuilder(endpointBuilder);
// 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
String key = "test/my_test中文.json";
String bucketName = "mybucket-1251668577";
String versionId = "xxxyyyzzz111222333";
System.out.println(cosclient.getObjectUrl(bucketName, key, versionId));
}
use of com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method initEncryptionClient.
protected static void initEncryptionClient() {
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
clientConfig = new ClientConfig(new Region(region));
if (generalApiEndpoint != null && generalApiEndpoint.trim().length() > 0 && serviceApiEndpoint != null && serviceApiEndpoint.trim().length() > 0) {
UserSpecifiedEndpointBuilder userSpecifiedEndpointBuilder = new UserSpecifiedEndpointBuilder(generalApiEndpoint, serviceApiEndpoint);
clientConfig.setEndpointBuilder(userSpecifiedEndpointBuilder);
}
EncryptionMaterialsProvider encryptionMaterialsProvider;
if (encryptionMaterials instanceof KMSEncryptionMaterials) {
KMSEncryptionMaterials kmsEncryptionMaterials = new KMSEncryptionMaterials(cmk);
encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kmsEncryptionMaterials);
} else {
encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider(encryptionMaterials);
}
cosclient = new COSEncryptionClient(qcloudkms, new COSStaticCredentialsProvider(cred), encryptionMaterialsProvider, clientConfig, cryptoConfiguration);
}
use of com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class GetAsyncFetchTaskDemo method getAsyncFetchTask.
public static void getAsyncFetchTask() {
EndpointBuilder builder = new UserSpecifiedEndpointBuilder(String.format("%s.migration.myqcloud.com", region), "service.cos.myqcloud.com");
COSClient cosClient = createCosClient();
cosClient.getClientConfig().setEndpointBuilder(builder);
GetAsyncFetchTaskRequest request = new GetAsyncFetchTaskRequest();
request.setBucketName(bucketName);
request.setTaskId(taskId);
GetAsyncFetchTaskResult result = cosClient.getAsyncFetchTask(request);
System.out.println(result.getCosRequestId());
System.out.println(result.getCode());
System.out.println(result.getMessage());
System.out.println(result.getRequestId());
for (Entry<String, String> entry : result.getData().entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
}
use of com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder in project cos-java-sdk-v5 by tencentyun.
the class PutAsyncFetchTaskDemo method putAsyncFetchTask.
public static void putAsyncFetchTask() {
EndpointBuilder builder = new UserSpecifiedEndpointBuilder(String.format("%s.migration.myqcloud.com", region), "service.cos.myqcloud.com");
COSClient cosClient = createCosClient();
cosClient.getClientConfig().setEndpointBuilder(builder);
PutAsyncFetchTaskRequest request = new PutAsyncFetchTaskRequest();
request.setBucketName(bucketName);
request.setUrl("https://pic1.zhimg.com/v2-63fc555d77019ae08ac2281a2418dcc7_720w.jpg");
request.setIgnoreSameKey(false);
request.setKey("test_fetch");
request.setOnKeyExist("override");
// 可选
// reqeust.setSuccessCallbackUrl("");
// request.setFailureCallbackUrl("");
// request.setMd5("");
PutAsyncFetchTaskResult result = cosClient.putAsyncFetchTask(request);
System.out.println(result.getCosRequestId());
System.out.println(result.getCode());
System.out.println(result.getMessage());
System.out.println(result.getRequestId());
for (Entry<String, String> entry : result.getData().entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
}
Aggregations