Skip to content

Commit

Permalink
Add s3 and fog for image saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Muncken87 committed Sep 5, 2016
1 parent 2b20eec commit 3c7d826
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@

# Ignore Byebug command history file.
.byebug_history

# Ignore application configuration
/config/application.yml
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ gem 'rmagick'
gem "animate-rails"
gem 'best_in_place', '~> 3.0.1'
gem 'simple_form'
gem 'carrierwave'
gem "fog-aws"
gem "figaro"

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
Expand Down
22 changes: 22 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,31 @@ GEM
responders
warden (~> 1.2.3)
erubis (2.7.0)
excon (0.50.1)
execjs (2.7.0)
ffi (1.9.14)
figaro (1.1.1)
thor (~> 0.14)
fog-aws (0.9.4)
fog-core (~> 1.38)
fog-json (~> 1.0)
fog-xml (~> 0.1)
ipaddress (~> 0.8)
fog-core (1.42.0)
builder
excon (~> 0.49)
formatador (~> 0.2)
fog-json (1.0.2)
fog-core (~> 1.0)
multi_json (~> 1.10)
fog-xml (0.1.2)
fog-core
nokogiri (~> 1.5, >= 1.5.11)
formatador (0.2.5)
globalid (0.3.7)
activesupport (>= 4.1.0)
i18n (0.7.0)
ipaddress (0.8.3)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
Expand Down Expand Up @@ -194,6 +214,8 @@ DEPENDENCIES
carrierwave
coffee-rails (~> 4.2)
devise
figaro
fog-aws
jbuilder (~> 2.5)
jquery-rails
jquery-ui-rails
Expand Down
8 changes: 7 additions & 1 deletion app/uploaders/avatar_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class AvatarUploader < CarrierWave::Uploader::Base
# include CarrierWave::MiniMagick
#include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
Expand All @@ -16,6 +15,13 @@ def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end


if Rails.env.production?
storage :fog
else
storage :file
end

def default_url
ActionController::Base.helpers.asset_path([version_name, "empty.jpg"].compact.join('_'))
end
Expand Down
24 changes: 24 additions & 0 deletions config/initializers/carrierwave.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# config/initializers/carrierwave.rb

CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
# Configuration for Amazon S3 should be made available through an Environment variable.
# For local installations, export the env variable through the shell OR
# if using Passenger, set an Apache environment variable.
#
# In Heroku, follow http://devcenter.heroku.com/articles/config-vars
#
# $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder

# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:region => ENV['AWS_REGION']
}


config.fog_directory = ENV['AWS_BUCKET']
# Generate http:// urls. Defaults to :authenticated_read (https://)
end
Binary file added public/uploads/user/avatar/1/Alex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/user/avatar/1/avatar_Alex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/user/avatar/1/mini_Alex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/user/avatar/1/slider_Alex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3c7d826

Please sign in to comment.