if you are looking to make use of your uploads using paperclip on AMAZON S3,then this is something that will help you.
i tried the same and wasted 5 days but its very easy by using ONLY aws-sdk gem and you can start uploading to S3.
Before starting i assume few thing from you:
- You have a running rails app ready.
- You have an active AMAZON S3 account (get the credentials,you will need it now)
- You are using paperclip 3.5.1(i prefer)
- You uploads are saving to your system locally
short preview of the sequence you need to understand:
START -> get aws-sdk gem -> create new s3.yml -> configure an initializer-paperclip.rb using AMAZON S3 credentials ----END----------THAT'S IT
lets get started:
- Install 'aws-sdk' gem by including in gemfile and running bundle install.
gem 'paperclip', '3.5.1'gem "aws-sdk"
- Create new yml file such as config/s3.yml and store your AMAZON S3 credentials as shown below:
development:
bucket:development_bucket
access_key_id: YOURACCESSKEY
bucket:development_bucket
access_key_id: YOURACCESSKEY
secret_access_key: YOURSECRETACCESSKEY
production:
bucket: production_bucket
access_key_id: YOURACCESSKEY
secret_access_key: YOURSECRETACCESSKEY
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:id/:filename'
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
4.add this to your image.rb or any other file using has_attached_file.
has_attached_file :avatar,
:storage =>:s3,
:s3_credentials => S3_CREDENTIALS
WE ARE DONE...start your uploads and check it on AWS MANAGEMENT CONSOLE in development bucket
Comments