use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class CompleteMultipartUpload method call.
@Override
public UploadResult call() throws Exception {
CompleteMultipartUploadResult res;
try {
CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest(origReq.getBucketName(), origReq.getKey(), uploadId, collectPartETags()).withGeneralProgressListener(origReq.getGeneralProgressListener());
ObjectMetadata origMeta = origReq.getMetadata();
if (origMeta != null) {
ObjectMetadata objMeta = req.getObjectMetadata();
if (objMeta == null) {
objMeta = new ObjectMetadata();
}
objMeta.setUserMetadata(origMeta.getUserMetadata());
req.setObjectMetadata(objMeta);
}
if (origReq.getPicOperations() != null) {
req.setPicOperations(origReq.getPicOperations());
}
TransferManagerUtils.populateEndpointAddr(origReq, req);
res = cos.completeMultipartUpload(req);
} catch (Exception e) {
monitor.uploadFailed();
throw e;
}
UploadResult uploadResult = new UploadResult();
uploadResult.setBucketName(origReq.getBucketName());
uploadResult.setKey(origReq.getKey());
uploadResult.setETag(res.getETag());
uploadResult.setVersionId(res.getVersionId());
uploadResult.setRequestId(res.getRequestId());
uploadResult.setDateStr(res.getDateStr());
uploadResult.setCrc64Ecma(res.getCrc64Ecma());
uploadResult.setCiUploadResult(res.getCiUploadResult());
monitor.uploadComplete();
return uploadResult;
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class KMSEncryptionClientDemo method getObjectDemo.
static void getObjectDemo() {
// 下载文件
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
File downloadFile = new File("downlen1m.txt");
ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
System.out.println(objectMetadata.getRequestId());
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class AsymmetricKeyEncryptionClientDemo method getObjectDemo.
static void getObjectDemo() {
// 下载文件
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
File downloadFile = new File("downAsy.txt");
ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
System.out.println(objectMetadata.getRequestId());
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class CAMRoleDemo method SimpleUploadFileFromEMR.
public static void SimpleUploadFileFromEMR() {
InstanceMetadataCredentialsEndpointProvider endpointProvider = new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.EMR);
InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
COSCredentials cred = cosCredentialsProvider.getCredentials();
System.out.println(cred.getCOSAccessKeyId());
System.out.println(cred.getCOSSecretKey());
System.out.println(cred.getCOSAppId());
ClientConfig clientConfig = new ClientConfig(new Region("ap-chongqing"));
COSClient cosClient = new COSClient(cosCredentialsProvider, clientConfig);
String bucketName = "aaa-125xxx";
String key = "test_emr.txt";
File localFile = new File("./test");
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
putObjectRequest.setStorageClass(StorageClass.Standard);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println("upload file etag: " + putObjectResult.getETag());
System.out.println("upload file requestId: " + putObjectResult.getRequestId());
ObjectMetadata getMeta = cosClient.getObjectMetadata(bucketName, key);
System.out.println("get file etag: " + getMeta.getETag());
cosClient.deleteObject(bucketName, key);
if (cosClient.doesObjectExist(bucketName, key)) {
System.out.println("delete failed");
} else {
System.out.println("delete successfully");
}
cosClient.shutdown();
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class GetObjectMetadataDemo method getObjectMetadataDemo.
// 将本地文件上传到COS
public static void getObjectMetadataDemo() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-beijing-1"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa/bbb.txt";
ObjectMetadata objectMetadata = cosclient.getObjectMetadata(bucketName, key);
System.out.println(objectMetadata.getCrc64Ecma());
System.out.println(objectMetadata.getLastModified());
// 关闭客户端
cosclient.shutdown();
}
Aggregations