kaya_
kaya_

Reputation: 107

set up expiration for putObject in s3 php sdk

This is working codes for creating bucket and putObject:

$bucket = uniqid("php-sdk-sample-", true);
echo "Creating bucket named {$bucket}\n";
$result = $client->createBucket(array(
'Bucket' => $bucket
));
// Wait until the bucket is created
$key = 'hello_world.txt';
echo "Creating a new object with key {$key}\n";
$result = $client->createObject(array(
'Bucket' => $bucket,
'Key'    => $key,
'Body'   => "Hello World!" 
));

How can I set up expiration date for this just created object ? For ex. I want to see disappear the uploaded file 3 days later.

Upvotes: 2

Views: 3285

Answers (2)

kaya_
kaya_

Reputation: 107

I figured it out. although its not working with sdk 2.6.*, this solved the problem ; create_object_expiration_config ( $bucket, $opt ) in sdk 1.6.2.

this is link.

Upvotes: 0

Jeremy Lindblom
Jeremy Lindblom

Reputation: 6517

You need to read and learn about S3 object lifecycle management first, then you can use the putBucketLifecycle operation to configure it.

Upvotes: 2

Related Questions