英文:
i want to set s3 object specific retention
问题
我想设置对象特定的保留期,但是使用以下 Java 代码没有成功:
所以我尝试锁定对象,但是我得到了以下错误:
Bucket 缺少 ObjectLockConfiguration
注意:已经为用户提供了完整的 S3 访问权限
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(bytes.length);
metadata.setContentType(contentType);
metadata.setExpirationTime(DateTime.now().toDate());
metadata.setHeader("x-amz-bucket-object-lock-enabled", true);
//metadata.setHeader("expires", expirationTime);
//metadata.setHttpExpiresDate(expirationTime);
ObjectLockConfiguration oc = new ObjectLockConfiguration();
PutObjectRequest putRequest = new PutObjectRequest(targetBucketName, objectName, baInputStream, metadata);
putRequest.setObjectLockRetainUntilDate(DateTime.now().plusDays(2).toDate());
s3client.putObject(putRequest);
英文:
i want to set object-specific retention but not successful with below java code:
So I try to lock the object but i am getting below error:
Bucket is missing ObjectLockConfiguration
Note: already provided full s3 access to the user
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(bytes.length);
metadata.setContentType(contentType);
metadata.setExpirationTime(DateTime.now().toDate());
metadata.setHeader("x-amz-bucket-object-lock-enabled", true);
//metadata.setHeader("expires", expirationTime);
//metadata.setHttpExpiresDate(expirationTime);
ObjectLockConfiguration oc = new ObjectLockConfiguration();
PutObjectRequest putRequest = new PutObjectRequest(targetBucketName, objectName, baInputStream, metadata);
putRequest.setObjectLockRetainUntilDate(DateTime.now().plusDays(2).toDate());
s3client.putObject(putRequest);
答案1
得分: 0
ObjectMetadata metadata = new ObjectMetadata();
System.out.println("size:" + bytes.length);
metadata.setContentLength(bytes.length);
metadata.setContentType(contentType);
Date expirationTime = new Date(2025, 5, 10);
metadata.setExpirationTime(DateTime.now().toDate());
metadata.setHeader("x-amz-object-lock-retain-until-date", closerDate + "T00:00:00.000Z");
metadata.setHeader("x-amz-object-lock-mode", "COMPLIANCE");
byte[] md5 = Md5Utils.computeMD5Hash(baInputStream);
String md5Base64 = BinaryUtils.toBase64(md5);
metadata.setHeader("Content-MD5", md5Base64);
baInputStream.reset();
PutObjectRequest putRequest = new PutObjectRequest(targetBucketName, objectName, baInputStream, metadata);
s3client.putObject(putRequest);
英文:
ObjectMetadata metadata = new ObjectMetadata();
System.out.println("size:"+bytes.length);
metadata.setContentLength(bytes.length);
metadata.setContentType(contentType);
Date expirationTime = new Date(2025,5,10);
metadata.setExpirationTime(DateTime.now().toDate());
metadata.setHeader("x-amz-object-lock-retain-until-date", closerDate+"T00:00:00.000Z");
metadata.setHeader("x-amz-object-lock-mode","COMPLIANCE");
byte[] md5 = Md5Utils.computeMD5Hash(baInputStream);
String md5Base64 = BinaryUtils.toBase64(md5);
metadata.setHeader("Content-MD5", md5Base64);
baInputStream.reset();
PutObjectRequest putRequest = new PutObjectRequest(targetBucketName, objectName, baInputStream, metadata);
s3client.putObject(putRequest);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论