Skip to content

Instantly share code, notes, and snippets.

@hughevans
Created April 21, 2013 23:23
Show Gist options
  • Select an option

  • Save hughevans/5431528 to your computer and use it in GitHub Desktop.

Select an option

Save hughevans/5431528 to your computer and use it in GitHub Desktop.
require 'aws-sdk'
AWS.config({
access_key_id: '',
secret_access_key: ''
})
s3 = AWS::S3.new
bucket = s3.buckets['bucket-name']
bucket.objects.each do |obj|
puts "Updating #{obj.key}"
content_type = case obj.key.split('.')[1]
when 'png'
'image/png'
when 'jpg'
'image/jpeg'
when 'jpeg'
'image/jpeg'
when 'gif'
'image/gif'
end
obj.copy_from(
obj.key,
{
:metadata => {},
:acl => :public_read,
:content_type => content_type,
:cache_control => 'max-age=4838400, public',
:expires => 'Wed, 19 Apr 2023 23:10:13 GMT+00:00',
}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment