[英]expiration object s3 through php sdk
I want to set an expiration date for an object on s3 I create the object like this:我想在 s3 上为对象设置到期日期我创建这样的对象:
$this->s3->putObject(array(
'Bucket' => BUCKET,
'Key'=> "path",
'SourceFile' => $fileTmp,
'Expires' => time()+2*60,
'ACL' => 'private'
));
But when I check file on aws S3 Console the object keeps:但是当我在 aws S3 Console 上检查文件时,对象会保留:
Expiry Date: None
Expiration Rule: N/A
How can I set object expiration?如何设置对象过期时间?
Use the putBucketLifecycle
method like that:像这样使用
putBucketLifecycle
方法:
$result = $client->putBucketLifecycleConfiguration([
'Bucket' => '<string>', // REQUIRED
'LifecycleConfiguration' => [
'Rules' => [ // REQUIRED
[
'Expiration' => [
'Date' => <integer || string || DateTime>,
'Days' => <integer>,
'ExpiredObjectDeleteMarker' => true || false,
],
'ID' => '<string>',
'Prefix' => '<string>',
'Status' => 'Enabled|Disabled', // REQUIRED
],
// ...
],
],
]);
Note笔记
getBucketLifecycleConfiguration
before and merge the previous rules with the new one.getBucketLifecycleConfiguration
并将以前的规则与新规则合并。 Resources资源
https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putbucketlifecycleconfiguration https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putbucketlifecycleconfiguration
Lifecycle policies are set per bucket, not per file.生命周期策略是按桶设置的,而不是按文件设置的。
Here's how to set a Lifecycle policy for a bucket:以下是为存储桶设置生命周期策略的方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.