Skip to content

Commit

Permalink
Partial set up for AmazonS3 and Dropbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Dec 11, 2013
1 parent 0244474 commit 2557bd5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -185,4 +191,4 @@ DEPENDENCIES
sqlite3
turbolinks
uglifier (>= 1.3.0)
will_paginate (= 3.0.3)
will_paginate (~> 3.0.3)
8 changes: 7 additions & 1 deletion app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down
6 changes: 6 additions & 0 deletions config/extras/dropbox.yml
Original file line number Diff line number Diff line change
@@ -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"] %>
3 changes: 2 additions & 1 deletion config/initializers/paperclip.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# config/initializers/paperclip.rb
Paperclip::Attachment.default_options[:s3_host_name] = 's3.amazonaws.com'
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'
5 changes: 2 additions & 3 deletions lib/tasks/populateimages3.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2557bd5

Please sign in to comment.