Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Metrics/BlockLength:
- "spec/**/*"

Metrics/ClassLength:
Max: 102
Max: 105

Naming/FileName:
Exclude:
Expand Down
9 changes: 8 additions & 1 deletion lib/carrierwave/storage/aws_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ def store(new_file)
if new_file.is_a?(self.class)
new_file.move_to(path)
else
file.upload_file(new_file.path, aws_options.write_options(new_file))
if Aws::S3.const_defined?(:TransferManager)
options = aws_options.write_options(new_file).except(:body)
options[:multipart_threshold] = AWSOptions::MULTIPART_THRESHOLD
Aws::S3::TransferManager.new(client: connection.client).upload_file(new_file.path, bucket: bucket.name,
key: path, **options)
else
file.upload_file(new_file.path, aws_options.write_options(new_file))
end
end
end

Expand Down
21 changes: 18 additions & 3 deletions spec/carrierwave/storage/aws_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,24 @@
CarrierWave::SanitizedFile.new('spec/fixtures/image.png')
end

it 'uploads the file using with multipart support' do
expect(file).to(receive(:upload_file)
.with(new_file.path, an_instance_of(Hash)))
it 'uploads the file using TransferManager' do
transfer_manager = instance_double('Aws::S3::TransferManager')
client = instance_double('Aws::S3::Client')

allow(bucket).to receive(:name).and_return('example-com')
allow(connection).to receive(:client).and_return(client)
allow(Aws::S3::TransferManager).to receive(:new).with(client: client).and_return(transfer_manager)

expect(transfer_manager).to receive(:upload_file).with(
new_file.path,
bucket: 'example-com',
key: path,
acl: :'public-read',
content_type: new_file.content_type,
encryption_key: 'def',
multipart_threshold: CarrierWave::Storage::AWSOptions::MULTIPART_THRESHOLD
)

aws_file.store(new_file)
end
end
Expand Down