mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 05:02:50 +08:00
Add subfolder option to S3 bucket config [SCI-2727]
This commit is contained in:
parent
eb2bf184b2
commit
32536db171
1 changed files with 22 additions and 19 deletions
|
@ -13,26 +13,32 @@ Paperclip::Attachment.default_options.merge!(
|
||||||
|
|
||||||
Paperclip::UriAdapter.register
|
Paperclip::UriAdapter.register
|
||||||
|
|
||||||
if ENV['PAPERCLIP_STORAGE'] == "s3"
|
if ENV['PAPERCLIP_STORAGE'] == 's3'
|
||||||
|
if ENV['S3_BUCKET'].nil? || ENV['AWS_REGION'].nil? ||
|
||||||
if ENV['S3_BUCKET'].nil? or ENV['AWS_REGION'].nil? or
|
ENV['AWS_ACCESS_KEY_ID'].nil? || ENV['AWS_SECRET_ACCESS_KEY'].nil?
|
||||||
ENV['AWS_ACCESS_KEY_ID'].nil? or ENV['AWS_SECRET_ACCESS_KEY'].nil?
|
puts 'WARNING! Environment variables S3_BUCKET, AWS_REGION, '\
|
||||||
puts "WARNING! Environment variables S3_BUCKET, AWS_REGION, " +
|
'AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set.'
|
||||||
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set."
|
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
Paperclip::Attachment.default_options.merge!({
|
|
||||||
|
s3_credentials = { bucket: ENV['S3_BUCKET'] }
|
||||||
|
|
||||||
|
if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
|
||||||
|
s3_credentials[:access_key_id] = ENV['AWS_ACCESS_KEY_ID']
|
||||||
|
s3_credentials[:secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
|
||||||
|
end
|
||||||
|
|
||||||
|
s3_path = '/:class/:attachment/:id_partition/:hash/:style/:filename'
|
||||||
|
s3_path.prepend("/#{ENV['S3_SUBFOLDER']}") if ENV['S3_SUBFOLDER']
|
||||||
|
|
||||||
|
Paperclip::Attachment.default_options.merge!(
|
||||||
url: ':s3_domain_url',
|
url: ':s3_domain_url',
|
||||||
path: '/:class/:attachment/:id_partition/:hash/:style/:filename',
|
path: s3_path,
|
||||||
storage: :s3,
|
storage: :s3,
|
||||||
s3_region: ENV['AWS_REGION'],
|
s3_region: ENV['AWS_REGION'],
|
||||||
s3_host_name: "s3.#{ENV['AWS_REGION']}.amazonaws.com",
|
s3_host_name: "s3.#{ENV['AWS_REGION']}.amazonaws.com",
|
||||||
s3_protocol: 'https',
|
s3_protocol: 'https',
|
||||||
s3_credentials: {
|
s3_credentials: s3_credentials,
|
||||||
bucket: ENV['S3_BUCKET'],
|
|
||||||
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
|
||||||
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
|
||||||
},
|
|
||||||
s3_permissions: {
|
s3_permissions: {
|
||||||
original: :private,
|
original: :private,
|
||||||
medium: :private
|
medium: :private
|
||||||
|
@ -43,12 +49,9 @@ if ENV['PAPERCLIP_STORAGE'] == "s3"
|
||||||
icon: :REDUCED_REDUNDANCY,
|
icon: :REDUCED_REDUNDANCY,
|
||||||
icon_small: :REDUCED_REDUNDANCY
|
icon_small: :REDUCED_REDUNDANCY
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
elsif ENV['PAPERCLIP_STORAGE'] == "filesystem"
|
elsif ENV['PAPERCLIP_STORAGE'] == 'filesystem'
|
||||||
Paperclip::Attachment.default_options.merge!({
|
Paperclip::Attachment.default_options[:storage] = :filesystem
|
||||||
storage: :filesystem
|
|
||||||
})
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Paperclip::Attachment.class_eval do
|
Paperclip::Attachment.class_eval do
|
||||||
|
|
Loading…
Reference in a new issue