Search in sources :

Example 1 with UserSpecifiedEndpointBuilder

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));
}
Also used : COSClient(com.qcloud.cos.COSClient) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) COSCredentials(com.qcloud.cos.auth.COSCredentials) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) Region(com.qcloud.cos.region.Region) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) ClientConfig(com.qcloud.cos.ClientConfig)

Example 2 with UserSpecifiedEndpointBuilder

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);
}
Also used : COSStaticCredentialsProvider(com.qcloud.cos.auth.COSStaticCredentialsProvider) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) StaticEncryptionMaterialsProvider(com.qcloud.cos.internal.crypto.StaticEncryptionMaterialsProvider) EncryptionMaterialsProvider(com.qcloud.cos.internal.crypto.EncryptionMaterialsProvider) KMSEncryptionMaterialsProvider(com.qcloud.cos.internal.crypto.KMSEncryptionMaterialsProvider) KMSEncryptionMaterialsProvider(com.qcloud.cos.internal.crypto.KMSEncryptionMaterialsProvider) Region(com.qcloud.cos.region.Region) StaticEncryptionMaterialsProvider(com.qcloud.cos.internal.crypto.StaticEncryptionMaterialsProvider) KMSEncryptionMaterials(com.qcloud.cos.internal.crypto.KMSEncryptionMaterials)

Example 3 with UserSpecifiedEndpointBuilder

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());
    }
}
Also used : COSClient(com.qcloud.cos.COSClient) GetAsyncFetchTaskResult(com.qcloud.cos.model.fetch.GetAsyncFetchTaskResult) GetAsyncFetchTaskRequest(com.qcloud.cos.model.fetch.GetAsyncFetchTaskRequest) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder)

Example 4 with UserSpecifiedEndpointBuilder

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());
    }
}
Also used : COSClient(com.qcloud.cos.COSClient) PutAsyncFetchTaskRequest(com.qcloud.cos.model.fetch.PutAsyncFetchTaskRequest) PutAsyncFetchTaskResult(com.qcloud.cos.model.fetch.PutAsyncFetchTaskResult) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) UserSpecifiedEndpointBuilder(com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder) EndpointBuilder(com.qcloud.cos.endpoint.EndpointBuilder)

Aggregations

UserSpecifiedEndpointBuilder (com.qcloud.cos.endpoint.UserSpecifiedEndpointBuilder)4 COSClient (com.qcloud.cos.COSClient)3 COSCredentials (com.qcloud.cos.auth.COSCredentials)2 EndpointBuilder (com.qcloud.cos.endpoint.EndpointBuilder)2 Region (com.qcloud.cos.region.Region)2 ClientConfig (com.qcloud.cos.ClientConfig)1 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSStaticCredentialsProvider (com.qcloud.cos.auth.COSStaticCredentialsProvider)1 EncryptionMaterialsProvider (com.qcloud.cos.internal.crypto.EncryptionMaterialsProvider)1 KMSEncryptionMaterials (com.qcloud.cos.internal.crypto.KMSEncryptionMaterials)1 KMSEncryptionMaterialsProvider (com.qcloud.cos.internal.crypto.KMSEncryptionMaterialsProvider)1 StaticEncryptionMaterialsProvider (com.qcloud.cos.internal.crypto.StaticEncryptionMaterialsProvider)1 GetAsyncFetchTaskRequest (com.qcloud.cos.model.fetch.GetAsyncFetchTaskRequest)1 GetAsyncFetchTaskResult (com.qcloud.cos.model.fetch.GetAsyncFetchTaskResult)1 PutAsyncFetchTaskRequest (com.qcloud.cos.model.fetch.PutAsyncFetchTaskRequest)1 PutAsyncFetchTaskResult (com.qcloud.cos.model.fetch.PutAsyncFetchTaskResult)1