use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class COSClient method invoke.
private <X, Y extends CosServiceRequest> X invoke(CosHttpRequest<Y> request, HttpResponseHandler<CosServiceResponse<X>> responseHandler) throws CosClientException, CosServiceException {
COSSigner cosSigner = clientConfig.getCosSigner();
COSCredentials cosCredentials;
CosServiceRequest cosServiceRequest = request.getOriginalRequest();
if (cosServiceRequest != null && cosServiceRequest.getCosCredentials() != null) {
cosCredentials = cosServiceRequest.getCosCredentials();
} else {
cosCredentials = fetchCredential();
}
Date expiredTime = new Date(System.currentTimeMillis() + clientConfig.getSignExpired() * 1000);
boolean isCIWorkflowRequest = cosServiceRequest instanceof CIWorkflowServiceRequest;
cosSigner.setCIWorkflowRequest(isCIWorkflowRequest);
cosSigner.sign(request, cosCredentials, expiredTime);
return this.cosHttpClient.exeute(request, responseHandler);
}
use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testRequestSpecifiedTmpKeyInfoPutGetDel.
@Test
public void testRequestSpecifiedTmpKeyInfoPutGetDel() throws CosServiceException, IOException, InterruptedException {
COSClient cosclient = buildTemporyCredentialsCOSClient(1800L);
File localFile = buildTestFile(1024L);
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
try {
String key = "ut/request-specified-key";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
putObjectRequest.setCosCredentials(cosCredentials);
cosclient.putObject(putObjectRequest);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
getObjectRequest.setCosCredentials(cosCredentials);
cosclient.getObject(getObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, key);
deleteObjectRequest.setCosCredentials(cosCredentials);
cosclient.deleteObject(deleteObjectRequest);
} finally {
localFile.delete();
cosclient.shutdown();
}
}
use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerTest method testTransferManagerCopySmallFileFromDiffRegion.
// transfer manager对不同园区5G以下文件进行使用put object copy
@Ignore
public void testTransferManagerCopySmallFileFromDiffRegion() throws CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
String srcRegion = "ap-guangzhou";
ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
String srcBucketName = "chengwus3gz-1251668577";
String srcKey = "ut_copy/len1G.txt";
String destKey = "ut_copy_dest/len1G.txt";
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(new Region(srcRegion), srcBucketName, srcKey, bucket, destKey);
Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
CopyResult copyResult = copy.waitForCopyResult();
assertNotNull(copyResult.getRequestId());
assertNotNull(copyResult.getDateStr());
clearObject(destKey);
}
use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerTest method testTransferManagerCopyBigFileFromSameRegion.
// transfer manager对相同园区使用put object copy
@Ignore
public void testTransferManagerCopyBigFileFromSameRegion() throws CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
String srcRegion = region;
ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
String srcBucketName = bucket;
String srcKey = "ut_copy/len10G_1.txt";
String destKey = "ut_copy_dest/len10G_2.txt";
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(new Region(srcRegion), srcBucketName, srcKey, bucket, destKey);
Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
CopyResult copyResult = copy.waitForCopyResult();
assertNotNull(copyResult.getRequestId());
assertNotNull(copyResult.getDateStr());
}
use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.
the class GetObjectURLDemo method getObjectUrlWithVersionId.
public static void getObjectUrlWithVersionId() {
// 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);
// 生成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));
}
Aggregations