Skip to content

Commit 77b3215

Browse files
authored
Merge pull request #2235 from jonodrew/aws-s3
Aws s3
2 parents 3c0a747 + 465bf01 commit 77b3215

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ gem 'bootsnap', require: false
99

1010
gem 'acts-as-taggable-on'
1111
gem 'carrierwave'
12-
gem 'carrierwave-ftp', github: 'luan/carrierwave-ftp', ref: '5481c13', require: 'carrierwave/storage/sftp'
1312
gem 'cocoon'
1413
gem 'delayed_job'
1514
gem 'delayed_job_active_record'
@@ -114,3 +113,5 @@ end
114113

115114
gem 'rollbar'
116115
gem 'skylight'
116+
117+
gem "carrierwave-aws", "~> 1.6"

Gemfile.lock

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
GIT
2-
remote: https://github.com/luan/carrierwave-ftp.git
3-
revision: 5481c1335fd3285d2057c7056e8a4662daa68dd4
4-
ref: 5481c13
5-
specs:
6-
carrierwave-ftp (0.4.1)
7-
carrierwave (>= 0.6.2)
8-
double-bag-ftps (~> 0.1.4)
9-
net-sftp (~> 4.0.0)
10-
111
GEM
122
remote: https://rubygems.org/
133
specs:
@@ -83,6 +73,24 @@ GEM
8373
ast (2.4.2)
8474
autoprefixer-rails (10.4.16.0)
8575
execjs (~> 2)
76+
aws-eventstream (1.4.0)
77+
aws-partitions (1.1137.0)
78+
aws-sdk-core (3.227.0)
79+
aws-eventstream (~> 1, >= 1.3.0)
80+
aws-partitions (~> 1, >= 1.992.0)
81+
aws-sigv4 (~> 1.9)
82+
base64
83+
jmespath (~> 1, >= 1.6.1)
84+
logger
85+
aws-sdk-kms (1.108.0)
86+
aws-sdk-core (~> 3, >= 3.227.0)
87+
aws-sigv4 (~> 1.5)
88+
aws-sdk-s3 (1.194.0)
89+
aws-sdk-core (~> 3, >= 3.227.0)
90+
aws-sdk-kms (~> 1)
91+
aws-sigv4 (~> 1.5)
92+
aws-sigv4 (1.12.1)
93+
aws-eventstream (~> 1, >= 1.0.2)
8694
base64 (0.2.0)
8795
better_errors (2.10.1)
8896
erubi (>= 1.0.0)
@@ -117,6 +125,9 @@ GEM
117125
image_processing (~> 1.1)
118126
marcel (~> 1.0.0)
119127
ssrf_filter (~> 1.0)
128+
carrierwave-aws (1.6.0)
129+
aws-sdk-s3 (~> 1.0)
130+
carrierwave (>= 2.0, < 4)
120131
childprocess (5.1.0)
121132
logger (~> 1.5)
122133
chosen-rails (1.10.0)
@@ -156,7 +167,6 @@ GEM
156167
dotenv-rails (3.1.0)
157168
dotenv (= 3.1.0)
158169
railties (>= 6.1)
159-
double-bag-ftps (0.1.4)
160170
erubi (1.13.1)
161171
execjs (2.10.0)
162172
fabrication (2.31.0)
@@ -198,6 +208,7 @@ GEM
198208
jbuilder (2.12.0)
199209
actionview (>= 5.0.0)
200210
activesupport (>= 5.0.0)
211+
jmespath (1.6.2)
201212
jquery-rails (4.6.0)
202213
rails-dom-testing (>= 1, < 3)
203214
railties (>= 4.2.0)
@@ -244,11 +255,8 @@ GEM
244255
net-protocol
245256
net-protocol (0.2.2)
246257
timeout
247-
net-sftp (4.0.0)
248-
net-ssh (>= 5.0.0, < 8.0.0)
249258
net-smtp (0.4.0.1)
250259
net-protocol
251-
net-ssh (7.2.0)
252260
nio4r (2.7.3)
253261
nokogiri (1.18.9)
254262
mini_portile2 (~> 2.8.2)
@@ -503,7 +511,7 @@ DEPENDENCIES
503511
bullet
504512
capybara
505513
carrierwave
506-
carrierwave-ftp!
514+
carrierwave-aws (~> 1.6)
507515
chosen-rails
508516
cocoon
509517
commonmarker

app/uploaders/avatar_uploader.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# encoding: utf-8
22

33
class AvatarUploader < CarrierWave::Uploader::Base
4-
storage :sftp if Rails.env.production?
4+
storage :s3 if Rails.env.production?
55

66
include CarrierWave::MiniMagick
77

8+
def content_type_allowlist
9+
[/image\//]
10+
end
11+
812
# Override the directory where uploaded files will be stored.
913
# This is a sensible default for uploaders that are meant to be mounted:
1014
def store_dir
11-
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
15+
"uploads/#{model.class.to_s.underscore}/#{model.id}"
1216
end
1317

1418
# Provide a default URL as a default if there hasn't been a file uploaded:

app/uploaders/image_uploader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ImageUploader < CarrierWave::Uploader::Base
2-
storage :sftp if Rails.env.production?
2+
storage :s3 if Rails.env.production?
33

44
# Include RMagick or MiniMagick support:
55
include CarrierWave::MiniMagick

config/initializers/carrier_wave.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
if Rails.env.development?
55
config.storage = :file
66
elsif Rails.env.production?
7-
config.cache_dir = "#{Rails.root}/tmp/uploads"
8-
config.root = Rails.root.join('tmp')
9-
config.sftp_host = ENV['UPLOADER_ASSET_HOST']
10-
config.sftp_user = ENV['UPLOADER_USER']
11-
config.sftp_folder = ENV['UPLOADER_FOLDER']
12-
config.sftp_url = ENV['UPLOADER_URL']
13-
config.sftp_options = {
14-
password: ENV['UPLOADER_PASSW'],
15-
port: 22
7+
config.storage = :aws
8+
config.aws_bucket = ENV.fetch('S3_BUCKET_NAME', 'prod-sponsor-logos')
9+
config.aws_acl = 'public-read'
10+
config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
11+
config.aws_credentials = {
12+
access_key_id: ENV.fetch('AWS_ACCESS_KEY'),
13+
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
14+
region: ENV.fetch('AWS_REGION', 'eu-north-1') # Required
1615
}
1716
end
1817
end

0 commit comments

Comments
 (0)