我想设置 S3 对象的特定保留期。

huangapple go评论75阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年4月10日 16:10:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/61136347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定