about summary refs log tree commit diff
path: root/lib/paperclip
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-10-18 18:29:04 +0200
committerGitHub <noreply@github.com>2021-10-18 18:29:04 +0200
commit6ba8bc45cb4f5ea6ab8ffc087feee7a089290b5c (patch)
tree91e8e187064b4f7d612e459716acc93bdd3a77df /lib/paperclip
parent9cdf8ac14843c222a2776567b926efcd9f4ccab1 (diff)
Add S3_FORCE_SINGLE_REQUEST env var to work around S3 compatibility issues (#16866)
Fixes #16822
Diffstat (limited to 'lib/paperclip')
-rw-r--r--lib/paperclip/storage_extensions.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/paperclip/storage_extensions.rb b/lib/paperclip/storage_extensions.rb
new file mode 100644
index 000000000..95c35641e
--- /dev/null
+++ b/lib/paperclip/storage_extensions.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+# Some S3-compatible providers might not actually be compatible with some APIs
+# used by kt-paperclip, see https://github.com/mastodon/mastodon/issues/16822
+if ENV['S3_ENABLED'] == 'true' && ENV['S3_FORCE_SINGLE_REQUEST'] == 'true'
+  module Paperclip
+    module Storage
+      module S3Extensions
+        def copy_to_local_file(style, local_dest_path)
+          log("copying #{path(style)} to local file #{local_dest_path}")
+          s3_object(style).download_file(local_dest_path, { mode: 'single_request' })
+        rescue Aws::Errors::ServiceError => e
+          warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
+          false
+        end
+      end
+    end
+  end
+
+  Paperclip::Storage::S3.prepend(Paperclip::Storage::S3Extensions)
+end