Skip to content

Commit

Permalink
Fix Cocaine::ExitStatusError when upload small non-animated GIF (#5489)
Browse files Browse the repository at this point in the history
Looks like copied tempfile need to be flushed before further processing. This issue won't happen if the uploaded file has enough file size.
  • Loading branch information
unarist committed Oct 26, 2017
1 parent 02f7f36 commit 4f337c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/paperclip/gif_transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def make
unless options[:style] == :original && num_frames > 1
tmp_file = Paperclip::TempfileFactory.new.generate(attachment.instance.file_file_name)
tmp_file << file.read
tmp_file.flush
return tmp_file
end

Expand Down
Binary file added spec/fixtures/files/mini-static.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 20 additions & 11 deletions spec/models/media_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@
end

describe 'non-animated gif non-conversion' do
let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('attachment.gif')) }
fixtures = [
{ filename: 'attachment.gif', width: 600, height: 400, aspect: 1.5 },
{ filename: 'mini-static.gif', width: 32, height: 32, aspect: 1.0 },
]

it 'sets type to image' do
expect(media.type).to eq 'image'
end
fixtures.each do |fixture|
context fixture[:filename] do
let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture(fixture[:filename])) }

it 'leaves original file as-is' do
expect(media.file_content_type).to eq 'image/gif'
end
it 'sets type to image' do
expect(media.type).to eq 'image'
end

it 'sets meta' do
expect(media.file.meta["original"]["width"]).to eq 600
expect(media.file.meta["original"]["height"]).to eq 400
expect(media.file.meta["original"]["aspect"]).to eq 1.5
it 'leaves original file as-is' do
expect(media.file_content_type).to eq 'image/gif'
end

it 'sets meta' do
expect(media.file.meta["original"]["width"]).to eq fixture[:width]
expect(media.file.meta["original"]["height"]).to eq fixture[:height]
expect(media.file.meta["original"]["aspect"]).to eq fixture[:aspect]
end
end
end
end

Expand Down

0 comments on commit 4f337c0

Please sign in to comment.