1 回答
TA贡献1895条经验 获得超3个赞
我弄清楚了问题所在。S3 对象的内容长度是加密的数据长度。但是当我放置对象时,我试图放置未加密的数据。因此,我需要将对象的内容长度显式设置为未加密的长度。下面的代码解决了这个问题。
try {
//Get the Source object stream
sourceS3Object = sourceS3Client.getObject(sourceS3Uri.getBucket(), sourceS3Uri.getKey());
//For a decrypted object, the content length in metadata has the encrypted length
//Set the content length to the unencrypted-data-length
ObjectMetadata objectMetadata = sourceS3Object.getObjectMetadata();
Map<String, String> modelMetaData = objectMetadata.getUserMetadata();
Long unencryptedDataLength = Long.parseLong(modelMetaData.get(
"x-amz-unencrypted-content-length"));
objectMetadata.setContentLength(unencryptedDataLength);
PutObjectRequest putRequest = new PutObjectRequest(destS3Uri.getBucket(), destS3Uri.getKey(),
sourceS3Object.getObjectContent(), objectMetadata);
eTag = destS3Client.putObject(putRequest).getETag();
if (eTag.isEmpty()) {
System.out.println("Copy failed, New object in " + destS3Uri.toString() + " is empty");
return false;
}
添加回答
举报