amazon-s3 - S3 java SDK - 设置对象过期

标签 amazon-s3 aws-sdk

我正在尝试将文件上传到 S3 并使用 Java SDK 为其设置过期日期。

这是我得到的代码:

   Instant expiration = Instant.now().plus(3, ChronoUnit.DAYS);
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setExpirationTime(Date.from(expiration));
            metadata.setHeader("Expires", Date.from(expiration));
            s3Client.putObject(bucketName, keyName, new FileInputStream(file), metadata);

该对象在 S3 控制台中没有过期数据。

我能做什么?

问候, 伊多

最佳答案

这是两个不相关的事情。控制台中显示的过期时间为 x-amz-expiration,由系统根据生命周期策略填充。它是只读的。

x-amz-expiration

Amazon S3 will return this header if an Expiration action is configured for the object as part of the bucket's lifecycle configuration. The header value includes an "expiry-date" component and a URL-encoded "rule-id" component.

https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html

Expires 是一个 header ,当在对象上设置该 header 时,该 header 会在下载对象时在响应中返回。

Expires

The date and time at which the object is no longer able to be cached. For more information, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21.

https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

无法告诉 S3 何时过期(删除)特定对象 - 这只能作为存储桶生命周期策略的一部分完成,如用户指南中 Object Lifecycle Management 下所述。 .

关于amazon-s3 - S3 java SDK - 设置对象过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48174550/

相关文章:

ssl - Amazon S3 数据完整性 MD5 与 SSL/TLS

node.js - 在 AWS Lambda 中使用托管在两个不同区域的两个不同的 AWS 资源?

aws-sdk - 错误 : Cannot find module '@aws-sdk/client-sns'

react-native - iOS 上的 AWSS3TransferUtilityErrorDomain 代码=2

java - 如果我想在用 Java 上传之前压缩视频,我有什么选择?

amazon-s3 - 有关 Amazon RDS、S3 存储和默认 RDS 表的基本问题

djangocollectstatic 与 django-storages 重新复制所有文件

node.js - 如何在KeystoneJS中上传S3文件

amazon-web-services - aws 容器服务中的 'cpu' 参数是什么意思?

javascript - 授予对 s3 目录的 Web 访问权限的最佳方法