Skip to content

Instantly share code, notes, and snippets.

@hasham2
Last active September 16, 2018 14:17
Show Gist options
  • Select an option

  • Save hasham2/8d424488932ac4360f0f to your computer and use it in GitHub Desktop.

Select an option

Save hasham2/8d424488932ac4360f0f to your computer and use it in GitHub Desktop.
Create s3 bucket and set CORS with Fog
# this goes into config/initializers/fog.rb
CONN = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'ACCESS_KEY',
:aws_secret_access_key => 'SECRET_KEY_HERE'
})
class User < ActiveRecord::Base
# All other code goes here
after_create :post_signup
def post_signip
CONN.put_bucket_cors 'newbucketname'
CONN.put_bucket_cors 'newbucketname', {"CORSConfiguration" => [{"AllowedOrigin" => ["*"],"AllowedHeader" => ["Content-Length", "X-Foobar"],"AllowedMethod" => ["PUT", "GET"],"MaxAgeSeconds" => 3000,"ExposeHeader" => ["x-amz-server-side-encryption", "x-amz-balls"]}]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment