gpt4 book ai didi

java - 我想设置 s3 对象特定保留

转载 作者:行者123 更新时间:2023-12-01 17:30:15 28 4
gpt4 key购买 nike

我想设置特定于对象的保留,但使用下面的 java 代码没有成功:

所以我尝试锁定对象,但出现以下错误:存储桶缺少 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);

最佳答案

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

关于java - 我想设置 s3 对象特定保留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61136347/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com