File tree Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Expand file tree Collapse file tree 3 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 11# encoding: utf-8
22
33class 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:
Original file line number Diff line number Diff line change 11class 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
Original file line number Diff line number Diff line change 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
1817end
You can’t perform that action at this time.
0 commit comments