From ed58cc3f47706985b08753979fdf9ef798105e16 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Wed, 17 May 2017 17:38:17 +0100 Subject: [PATCH] Handle multipart upload of empty files --- lib/fog/aws/models/storage/file.rb | 5 +++++ tests/models/storage/file_tests.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/fog/aws/models/storage/file.rb b/lib/fog/aws/models/storage/file.rb index 6336d8716..df042a684 100644 --- a/lib/fog/aws/models/storage/file.rb +++ b/lib/fog/aws/models/storage/file.rb @@ -276,6 +276,11 @@ module Fog part_tags << part_upload.headers["ETag"] end + if part_tags.empty? #it is an error to have a multipart upload with no parts + part_upload = service.upload_part(directory.key, key, upload_id, 1, '', part_headers('', options)) + part_tags << part_upload.headers["ETag"] + end + rescue # Abort the upload & reraise service.abort_multipart_upload(directory.key, key, upload_id) if upload_id diff --git a/tests/models/storage/file_tests.rb b/tests/models/storage/file_tests.rb index d4dc9fef0..1c3c7ce33 100644 --- a/tests/models/storage/file_tests.rb +++ b/tests/models/storage/file_tests.rb @@ -74,6 +74,18 @@ Shindo.tests("Storage[:aws] | file", ["aws"]) do end + tests("multipart upload with empty file") do + pending if Fog.mocking? + + @empty_file = Tempfile.new("fog-test-aws-s3-multipart-empty") + + tests("#save(:multipart_chunk_size => 5242880)").succeeds do + @directory.files.create(:key => 'empty-multipart-upload', :body => @empty_file, :multipart_chunk_size => 5242880) + end + + @empty_file.close + end + tests("multipart upload with customer encryption").returns(true) do pending if Fog.mocking?