Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Thank you @excid3 for suggestion.

Closes #582
  • Loading branch information...
commit 23cd662e438fd9a44c09c2ac75cccc4a6673858d 1 parent cb6efaa
Chris Oliver and Prem Sichanugrist authored sikachu committed
View
2  lib/paperclip/upfile.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
View
1  test/fixtures/text.txt
@@ -0,0 +1 @@
+paperclip!
View
16 test/upfile_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.