From 2557bd5feaae44ae1acb1b106e15929465395929 Mon Sep 17 00:00:00 2001 From: Neil Gehani Date: Tue, 10 Dec 2013 19:58:36 -0800 Subject: [PATCH] Partial set up for AmazonS3 and Dropbox --- Gemfile | 5 +++-- Gemfile.lock | 10 ++++++++-- app/models/pin.rb | 8 +++++++- config/environments/production.rb | 4 ++-- config/extras/dropbox.yml | 6 ++++++ config/initializers/paperclip.rb | 3 ++- lib/tasks/populateimages3.rake | 5 ++--- 7 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 config/extras/dropbox.yml diff --git a/Gemfile b/Gemfile index bdeaad5..2185b18 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,11 @@ gem 'jquery-rails' gem 'devise', '~> 3.1.1' gem 'simple_form', '~> 3.0.0.rc' gem "paperclip", "~> 3.0" +gem "paperclip-dropbox" gem 'aws-sdk', '~> 1.5.7' gem "masonry-rails", '~> 0.2.0' -gem 'faker' -gem 'will_paginate', '3.0.3' +gem 'faker', "~> 1.2.0" +gem 'will_paginate', '~> 3.0.3' gem 'bootstrap-will_paginate' gem 'acts_as_follower' diff --git a/Gemfile.lock b/Gemfile.lock index fd8b985..68f36d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,6 +56,8 @@ GEM railties (>= 3.2.6, < 5) thread_safe (~> 0.1) warden (~> 1.2.3) + dropbox-sdk (1.6.2) + json erubis (2.7.0) execjs (2.0.2) faker (1.2.0) @@ -92,6 +94,9 @@ GEM activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types + paperclip-dropbox (1.1.7) + dropbox-sdk (~> 1.3) + paperclip (~> 3.1) pg (0.17.0) polyglot (0.3.3) protected_attributes (1.0.3) @@ -169,12 +174,13 @@ DEPENDENCIES bootstrap-will_paginate coffee-rails (~> 4.0.0) devise (~> 3.1.1) - faker + faker (~> 1.2.0) jbuilder (= 1.2) jquery-rails jquery-turbolinks masonry-rails (~> 0.2.0) paperclip (~> 3.0) + paperclip-dropbox pg protected_attributes rails (= 4.0.0) @@ -185,4 +191,4 @@ DEPENDENCIES sqlite3 turbolinks uglifier (>= 1.3.0) - will_paginate (= 3.0.3) + will_paginate (~> 3.0.3) diff --git a/app/models/pin.rb b/app/models/pin.rb index 3896643..df46935 100644 --- a/app/models/pin.rb +++ b/app/models/pin.rb @@ -9,7 +9,13 @@ class Pin < ActiveRecord::Base content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] }, size: { less_than: 5.megabytes } belongs_to :user - has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100" } + has_attached_file :image, + #:storage => :dropbox, + #:dropbox_credentials => "#{Rails.root}/config/dropbox.yml", + :styles => { :medium => "300x300>", :thumb => "100x100" } + #:dropbox_options => { + # :path => proc { |style| "#{style}/#{id}_#{image.original_filename}" } + #} def image_remote_url=(url_value) self.image = URI.parse(url_value) unless url_value.blank? diff --git a/config/environments/production.rb b/config/environments/production.rb index e5ede19..4ddcbc9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -84,8 +84,8 @@ # config heroku to us Amazon S3 to store files config.paperclip_defaults = { :storage => :s3, - :bucket => ENV['AWS_BUCKET'], - :s3_credentials => { + :s3_credentials => { + :bucket => ENV['AWS_BUCKET'], :access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] } diff --git a/config/extras/dropbox.yml b/config/extras/dropbox.yml new file mode 100644 index 0000000..171320b --- /dev/null +++ b/config/extras/dropbox.yml @@ -0,0 +1,6 @@ +app_key: <%= ENV["DROPBOX_APP_KEY"] %> +app_secret: <%= ENV["DROPBOX_APP_SECRET"] %> +access_token: <%= ENV["DROPBOX_ACCESS_TOKEN"] %> +access_token_secret: <%= ENV["DROPBOX_ACCESS_TOKEN_SECRET"] %> +user_id: <%= ENV["DROPBOX_USER_ID"] %> +access_type: <%= ENV["DROPBOX_ACCESS_TYPE"] %> diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 0f7fc66..b6b54d3 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,2 +1,3 @@ # config/initializers/paperclip.rb -Paperclip::Attachment.default_options[:s3_host_name] = 's3.amazonaws.com' \ No newline at end of file +Paperclip::Attachment.default_options[:url] = ':event_sample_images.s3-website-us-east-1.amazonaws.com' +Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' \ No newline at end of file diff --git a/lib/tasks/populateimages3.rake b/lib/tasks/populateimages3.rake index 502275c..468896e 100644 --- a/lib/tasks/populateimages3.rake +++ b/lib/tasks/populateimages3.rake @@ -3,11 +3,10 @@ namespace :db do desc "Fill database with sample data" task populateimages3: :environment do - User.all.each do |user| + User.all.each do |user| puts "[DEBUG] uploading images for user #{user.id} of #{User.last.id}" 10.times do |n| - #image = user.pins.create!(image_remote_url: 'http://s3.amazonaws.com/event_sample_images').sample, description: %w(cool awesome crazy wow adorbs incredible).sample - #image = image_remote_url('http://s3.amazonaws.com/event_sample_images').sample + #image = image_remote_url('https://event_sample_images.s3-website-us-east-1.amazonaws.com').sample #description = %w(cool awesome crazy wow adorbs incredible).sample #user.pins.create!(image: image, description: description) end