闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
1.1 KiB

  1. if ENV['S3_ENABLED'] == 'true'
  2. Aws.eager_autoload!(services: %w(S3))
  3. Paperclip::Attachment.default_options[:storage] = :s3
  4. Paperclip::Attachment.default_options[:s3_protocol] = 'https'
  5. Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
  6. Paperclip::Attachment.default_options[:s3_host_name] = "s3-#{ENV.fetch('S3_REGION')}.amazonaws.com"
  7. Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
  8. Paperclip::Attachment.default_options[:s3_headers] = { 'Cache-Control' => 'max-age=315576000', 'Expires' => 10.years.from_now.httpdate }
  9. unless ENV['S3_CLOUDFRONT_HOST'].blank?
  10. Paperclip::Attachment.default_options[:url] = ':s3_alias_url'
  11. Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
  12. end
  13. Paperclip::Attachment.default_options[:s3_credentials] = {
  14. bucket: ENV.fetch('S3_BUCKET'),
  15. access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
  16. secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
  17. s3_region: ENV.fetch('S3_REGION'),
  18. }
  19. end