Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Last active September 7, 2015 19:11
Show Gist options
  • Save joelibaceta/5d219ae4fe249b9ab36d to your computer and use it in GitHub Desktop.
Save joelibaceta/5d219ae4fe249b9ab36d to your computer and use it in GitHub Desktop.
PaperClip + S3 with a custom path
#config/initializers/paperclip.rb
Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename.#{Time.now.to_i}'
#config/environments/production.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
class SomeModel < ActiveRecord::Base
has_attached_file :avatar, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment