use of com.qcloud.cos.model.InitiateMultipartUploadResult in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method initiateMultipartUploadSecurely.
@Override
public InitiateMultipartUploadResult initiateMultipartUploadSecurely(InitiateMultipartUploadRequest req) {
// Generate a one-time use symmetric key and initialize a cipher to
// encrypt object data
ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req);
if (cryptoConfig.getStorageMode() == ObjectMetadata) {
ObjectMetadata metadata = req.getObjectMetadata();
if (metadata == null)
metadata = new ObjectMetadata();
long dataSize = req.getDataSize();
long partSize = req.getPartSize();
if (dataSize < 0 || partSize < 0) {
throw new CosClientException("initiate multipart upload with encryption client must set dataSize and partSize");
}
if (partSize % 16 != 0) {
throw new CosClientException("initiat multipart uplaod with encryption client must set part size a mutiple of 16" + "but got " + partSize);
}
metadata.addUserMetadata(Headers.ENCRYPTION_DATA_SIZE, Long.toString(dataSize));
metadata.addUserMetadata(Headers.ENCRYPTION_PART_SIZE, Long.toString(partSize));
// Store encryption info in metadata
req.setObjectMetadata(updateMetadataWithContentCryptoMaterial(metadata, null, cekMaterial));
}
InitiateMultipartUploadResult result = cos.initiateMultipartUpload(req);
MultipartUploadCryptoContext uploadContext = newUploadContext(req, cekMaterial);
if (req instanceof MaterialsDescriptionProvider) {
MaterialsDescriptionProvider p = (MaterialsDescriptionProvider) req;
uploadContext.setMaterialsDescription(p.getMaterialsDescription());
}
multipartUploadContexts.put(result.getUploadId(), uploadContext);
return result;
}
use of com.qcloud.cos.model.InitiateMultipartUploadResult in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method getUploadId.
/**
* get cos upload Id
* @param key cos key
* @return uploadId
* @throws IOException when fail to get the Multipart Upload ID.
*/
public String getUploadId(String key) throws IOException {
if (null == key || key.length() == 0) {
return "";
}
ObjectMetadata objectMetadata = new ObjectMetadata();
if (crc32cEnabled) {
objectMetadata.setHeader(Constants.CRC32C_REQ_HEADER, Constants.CRC32C_REQ_HEADER_VAL);
}
InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(bucketName, key);
if (null != this.storageClass) {
initiateMultipartUploadRequest.setStorageClass(this.storageClass);
}
initiateMultipartUploadRequest.setObjectMetadata(objectMetadata);
this.setEncryptionMetadata(initiateMultipartUploadRequest, objectMetadata);
try {
InitiateMultipartUploadResult initiateMultipartUploadResult = (InitiateMultipartUploadResult) this.callCOSClientWithRetry(initiateMultipartUploadRequest);
return initiateMultipartUploadResult.getUploadId();
} catch (Exception e) {
String errMsg = String.format("Get the upload id failed, cos key: %s, " + "exception: %s", key, e);
handleException(new Exception(errMsg), key);
}
return null;
}
use of com.qcloud.cos.model.InitiateMultipartUploadResult in project cos-java-sdk-v5 by tencentyun.
the class ImagePersistenceDemo method persistenceImageWithMultipart.
public static void persistenceImageWithMultipart(COSClient cosClient) throws FileNotFoundException {
// bucket名需包含appid
// api 请参考 https://cloud.tencent.com/document/product/436/54050
String bucketName = "examplebucket-1250000000";
String key = "test.jpg";
File localFile = new File("E://test.jpg");
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, key);
InitiateMultipartUploadResult initResult = cosClient.initiateMultipartUpload(request);
String uploadId = initResult.getUploadId();
// 上传分块
List<PartETag> partETags = new LinkedList<>();
UploadPartRequest uploadPartRequest = new UploadPartRequest();
uploadPartRequest.setBucketName(bucketName);
uploadPartRequest.setKey(key);
uploadPartRequest.setUploadId(uploadId);
// 设置分块的数据来源输入流
uploadPartRequest.setInputStream(new FileInputStream(localFile));
// 设置分块的长度
// 设置数据长度
uploadPartRequest.setPartSize(localFile.length());
// 假设要上传的part编号是10
uploadPartRequest.setPartNumber(1);
UploadPartResult uploadPartResult = cosClient.uploadPart(uploadPartRequest);
PartETag partETag = uploadPartResult.getPartETag();
partETags.add(partETag);
// 合并分块并带上图像处理参数
PicOperations picOperations = new PicOperations();
picOperations.setIsPicInfo(1);
List<PicOperations.Rule> ruleList = new LinkedList<>();
PicOperations.Rule rule1 = new PicOperations.Rule();
rule1.setBucket(bucketName);
rule1.setFileId("test-1.jpg");
rule1.setRule("imageMogr2/rotate/90");
ruleList.add(rule1);
PicOperations.Rule rule2 = new PicOperations.Rule();
rule2.setBucket(bucketName);
rule2.setFileId("test-2.jpg");
rule2.setRule("imageMogr2/rotate/180");
ruleList.add(rule2);
picOperations.setRules(ruleList);
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags);
completeMultipartUploadRequest.setPicOperations(picOperations);
CompleteMultipartUploadResult completeMultipartUploadResult = cosClient.completeMultipartUpload(completeMultipartUploadRequest);
// 获取图片处理的结果
CIUploadResult ciUploadResult = completeMultipartUploadResult.getCiUploadResult();
System.out.println(completeMultipartUploadResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
System.out.println(ciObject.getEtag());
}
}
Aggregations