Skip to content

Instantly share code, notes, and snippets.

@unixcharles
Created October 19, 2010 13:03
Show Gist options
  • Save unixcharles/634153 to your computer and use it in GitHub Desktop.
Save unixcharles/634153 to your computer and use it in GitHub Desktop.
Fix permission issue on Amazon S3. Restore to default paperclip setting
BUCKET = "teambox-assets"
# require 'aws/s3'
AWS::S3::Base.establish_connection!(:access_key_id => YOUR_ACCESS_KEY, :secret_access_key => YOUR_SECRET_KEY )
include AWS::S3
def set_public(key, bucket)
policy = S3Object.acl(key, bucket)
policy.grants << ACL::Grant.grant(:public_read)
policy.grants << ACL::Grant.grant(:public_read_acp)
S3Object.acl(key, bucket, policy)
end
Uploads = Upload.find(:all, :conditions => ?????)
count = Uploads.count
Uploads.each_with_index do |upload, index|
puts "#{((index.to_f / count.to_f ) * 100).to_i}% :: Fix permission for: #{upload.id} / #{upload.file_name}"
set_public(upload.asset.path(:thumb), BUCKET ) rescue puts "#{upload.id} fail for thumb. No thumb?"
set_public(upload.asset.path, BUCKET ) rescue puts "#{upload.id} fail for original. No file?"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment