Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multipart upload of empty files #365

Merged
merged 1 commit into from
May 18, 2017
Merged
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
5 changes: 5 additions & 0 deletions lib/fog/aws/models/storage/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def multipart_save(options)
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
Expand Down
12 changes: 12 additions & 0 deletions tests/models/storage/file_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@

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?

Expand Down