Commit 23cd662e by Chris Oliver and Prem Sichanugrist Committed by Prem Sichanugrist

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

Thank you @excid3 for suggestion.

Closes #582
parent cb6efaa5
...@@ -25,7 +25,7 @@ module Paperclip ...@@ -25,7 +25,7 @@ module Paperclip
def type_from_file_command def type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. # 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 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 = "application/x-#{type}" if mime_type.match(/\(.*?\)/)
mime_type mime_type
end end
......
...@@ -34,4 +34,20 @@ class UpfileTest < Test::Unit::TestCase ...@@ -34,4 +34,20 @@ class UpfileTest < Test::Unit::TestCase
end end
assert_equal 'text/plain', file.content_type assert_equal 'text/plain', file.content_type
end 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 end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment