From 4bc0dd751cbe776918be75fbdfefddca876edb81 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Thu, 10 Aug 2023 14:15:18 +0200
Subject: [PATCH] Add `S3_DISABLE_CHECKSUM_MODE` environment variable for
 compatibility with some S3-compatible providers (#26435)

---
 config/initializers/paperclip.rb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb
index 12d8d6934..02943ce09 100644
--- a/config/initializers/paperclip.rb
+++ b/config/initializers/paperclip.rb
@@ -90,13 +90,19 @@ if ENV['S3_ENABLED'] == '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_FORCE_SINGLE_REQUEST'] == 'true'
+  # and https://github.com/mastodon/mastodon/issues/26394
+  if ENV['S3_FORCE_SINGLE_REQUEST'] == 'true' || ENV['S3_DISABLE_CHECKSUM_MODE'] == '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' })
+
+            options = {}
+            options[:mode] = 'single_request' if ENV['S3_FORCE_SINGLE_REQUEST'] == 'true'
+            options[:checksum_mode] = 'DISABLED' if ENV['S3_DISABLE_CHECKSUM_MODE'] == 'true'
+
+            s3_object(style).download_file(local_dest_path, options)
           rescue Aws::Errors::ServiceError => e
             warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
             false