Permalink
Browse files

Use --mime instead of --mime-type for `file` command

Thank you @excid3 for suggestion.

Closes #582
  • Loading branch information...
1 parent cb6efaa commit 23cd662e438fd9a44c09c2ac75cccc4a6673858d Chris Oliver and Prem Sichanugrist committed with sikachu Sep 3, 2011
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/paperclip/upfile.rb
  2. +1 −0 test/fixtures/text.txt
  3. +16 −0 test/upfile_test.rb
@@ -25,7 +25,7 @@ def iterate_over_array_to_find_best_option(types)
def type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type = (self.original_filename.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
- mime_type = (Paperclip.run("file", "-b --mime-type :file", :file => self.path).split(':').last.strip rescue "application/x-#{type}")
+ mime_type = (Paperclip.run("file", "-b --mime :file", :file => self.path).split(/[:;]\s+/)[0] rescue "application/x-#{type}")
mime_type = "application/x-#{type}" if mime_type.match(/\(.*?\)/)
mime_type
end
@@ -0,0 +1 @@
+paperclip!
View
@@ -34,4 +34,20 @@ class << file
end
assert_equal 'text/plain', file.content_type
end
+
+ { '5k.png' => 'image/png',
+ 'animated.gif' => 'image/gif',
+ 'text.txt' => 'text/plain',
+ 'twopage.pdf' => 'application/pdf'
+ }.each do |filename, content_type|
+ should "return a content type of #{content_type} from a file command for file #{filename}" do
+ file = File.new(File.join(File.dirname(__FILE__), "fixtures", filename))
+ class << file
+ include Paperclip::Upfile
+ end
+
+ assert_equal content_type, file.type_from_file_command
+ end
+ end
+
end

0 comments on commit 23cd662

Please sign in to comment.