Commit 23ee8e6257f09172e30c2bd6fd1d1fcd4d4e58b3
1 parent
cde6b8e4
Exists in
master
and in
4 other branches
Init aws support for file storage
Showing
3 changed files
with
37 additions
and
0 deletions
Show diff stats
Gemfile
@@ -57,6 +57,8 @@ gem "haml-rails" | @@ -57,6 +57,8 @@ gem "haml-rails" | ||
57 | 57 | ||
58 | # Files attachments | 58 | # Files attachments |
59 | gem "carrierwave" | 59 | gem "carrierwave" |
60 | +# for aws storage | ||
61 | +# gem "fog", "~> 1.3.1" | ||
60 | 62 | ||
61 | # Authorization | 63 | # Authorization |
62 | gem "six" | 64 | gem "six" |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +# See https://github.com/jnicklas/carrierwave#using-amazon-s3 | ||
2 | +# for more options | ||
3 | +production: | ||
4 | + access_key_id: AKIA1111111111111UA | ||
5 | + secret_access_key: secret | ||
6 | + bucket: mygitlab.production.us | ||
7 | + region: us-east-1 | ||
8 | + | ||
9 | +development: | ||
10 | + access_key_id: AKIA1111111111111UA | ||
11 | + secret_access_key: secret | ||
12 | + bucket: mygitlab.development.us | ||
13 | + region: us-east-1 | ||
14 | + | ||
15 | +test: | ||
16 | + access_key_id: AKIA1111111111111UA | ||
17 | + secret_access_key: secret | ||
18 | + bucket: mygitlab.test.us | ||
19 | + region: us-east-1 |
config/initializers/carrierwave.rb
1 | CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ | 1 | CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ |
2 | + | ||
3 | +aws_file = Rails.root.join('config', 'aws.yml') | ||
4 | + | ||
5 | +if File.exists?(aws_file) | ||
6 | + AWS_CONFIG = YAML.load(File.read(aws_file))[Rails.env] | ||
7 | + | ||
8 | + config.fog_credentials = { | ||
9 | + provider: 'AWS', # required | ||
10 | + aws_access_key_id: AWS_CONFIG['access_key_id'], # required | ||
11 | + aws_secret_access_key: AWS_CONFIG['secret_access_key'], # required | ||
12 | + region: AWS_CONFIG['region'], # optional, defaults to 'us-east-1' | ||
13 | + } | ||
14 | + config.fog_directory = AWS_CONFIG['bucket'] # required | ||
15 | + config.fog_public = false # optional, defaults to true | ||
16 | + config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} | ||
17 | +end |