amazon s3 - Rails AWS-SDK: Set Expiration Date for Objects -
in rails app, allow users upload images directly s3, creates temporary file gets automatically deleted after image record saved in database.
instead of automatically deleting image after record saved, i'd set expiration date file on s3 automatically gets deleted after period (say 24 hours).
i've seen documentation on how set expiration date on bucket (http://docs.aws.amazon.com/awsrubysdk/latest/aws/s3/bucketlifecycleconfiguration.html), want folder within bucket have files automatically removed.
does have suggestions how it?
s3 = aws::s3.new(:access_key_id => env['aws_access_key_id'], :secret_access_key => env['aws_access_key']) foldername = @image.s3_filepath.split("/")[5] folder_path = 'uploads/' + foldername s3.buckets[env['aws_bucket']].objects.with_prefix(folder_path).each( #set expiration date header here)
you set lifecycle configuration on bucket itself, not each individual object. using rest api you'd write out xml configuration (there's field prefix
let's apply lifecycle config keys prefixed it) , put
bucket.
converting on ruby sdk, looks example is doing want; first parameter of add_rule appears prefix.
Comments
Post a Comment