summaryrefslogtreecommitdiff
path: root/config/initializers/carrierwave_patch.rb
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers/carrierwave_patch.rb')
-rw-r--r--config/initializers/carrierwave_patch.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/config/initializers/carrierwave_patch.rb b/config/initializers/carrierwave_patch.rb
index ad3ff36138f..c8c6f75949c 100644
--- a/config/initializers/carrierwave_patch.rb
+++ b/config/initializers/carrierwave_patch.rb
@@ -17,7 +17,24 @@ module CarrierWave
class Fog < Abstract
class File
def copy_to(new_path)
- connection.copy_object(@uploader.fog_directory, file.key, @uploader.fog_directory, new_path, copy_to_options)
+ # fog-aws needs multipart uploads to copy files above 5 GB,
+ # and it is currently the only Fog provider that supports
+ # multithreaded uploads (https://github.com/fog/fog-aws/pull/579).
+ # Multithreaded uploads are essential for copying large amounts of data
+ # within the request timeout.
+ if ::Feature.enabled?(:s3_multithreaded_uploads, default_enabled: true) && fog_provider == 'AWS'
+ # AWS SDK uses 10 threads by default and a multipart chunk size of 10 MB
+ file.concurrency = 10
+ file.multipart_chunk_size = 10485760
+ file.copy(@uploader.fog_directory, new_path, copy_to_options)
+ else
+ # Some Fog providers may issue a GET request (https://github.com/fog/fog-google/issues/512)
+ # instead of a HEAD request after the transfer completes,
+ # which might cause the file to be downloaded locally.
+ # We fallback to the original copy_object for non-AWS providers.
+ connection.copy_object(@uploader.fog_directory, file.key, @uploader.fog_directory, new_path, copy_to_options)
+ end
+
CarrierWave::Storage::Fog::File.new(@uploader, @base, new_path)
end