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 1
1
# encoding: utf-8
2
2
3
3
class AvatarUploader < CarrierWave ::Uploader ::Base
4
- storage :sftp if Rails . env . production?
4
+ storage :s3 if Rails . env . production?
5
5
6
6
include CarrierWave ::MiniMagick
7
7
8
+ def content_type_allowlist
9
+ [ /image\/ / ]
10
+ end
11
+
8
12
# Override the directory where uploaded files will be stored.
9
13
# This is a sensible default for uploaders that are meant to be mounted:
10
14
def store_dir
11
- "uploads/#{ model . class . to_s . underscore } /#{ mounted_as } / #{ model . id } "
15
+ "uploads/#{ model . class . to_s . underscore } /#{ model . id } "
12
16
end
13
17
14
18
# 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 1
1
class ImageUploader < CarrierWave ::Uploader ::Base
2
- storage :sftp if Rails . env . production?
2
+ storage :s3 if Rails . env . production?
3
3
4
4
# Include RMagick or MiniMagick support:
5
5
include CarrierWave ::MiniMagick
Original file line number Diff line number Diff line change 4
4
if Rails . env . development?
5
5
config . storage = :file
6
6
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
16
15
}
17
16
end
18
17
end
You can’t perform that action at this time.
0 commit comments