1
0

storage_extensions.rb 796 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. # Some S3-compatible providers might not actually be compatible with some APIs
  3. # used by kt-paperclip, see https://github.com/mastodon/mastodon/issues/16822
  4. if ENV['S3_ENABLED'] == 'true' && ENV['S3_FORCE_SINGLE_REQUEST'] == 'true'
  5. module Paperclip
  6. module Storage
  7. module S3Extensions
  8. def copy_to_local_file(style, local_dest_path)
  9. log("copying #{path(style)} to local file #{local_dest_path}")
  10. s3_object(style).download_file(local_dest_path, { mode: 'single_request' })
  11. rescue Aws::Errors::ServiceError => e
  12. warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
  13. false
  14. end
  15. end
  16. end
  17. end
  18. Paperclip::Storage::S3.prepend(Paperclip::Storage::S3Extensions)
  19. end