我想设置 s3 对象特定保留

i want to set s3 object specific retention

我想设置特定于对象的保留,但使用以下 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);