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.

34 lines
1.5 KiB

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