Commit 8c7c1e89 by Jon Yurek

Handling the file command, added after the initial rails3 branch.

parent 488ffd25
...@@ -16,7 +16,10 @@ module Paperclip ...@@ -16,7 +16,10 @@ module Paperclip
when "js" then "application/js" when "js" then "application/js"
when "csv", "xml", "css" then "text/#{type}" when "csv", "xml", "css" then "text/#{type}"
else else
Paperclip.run("file", "--mime-type #{self.path}").split(':').last.strip rescue "application/x-#{type}" # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
content_type = (Paperclip.run("file", "--mime-type #{self.path}").split(':').last.strip rescue "application/x-#{type}")
content_type = "application/x-#{type}" if content_type.match(/\(.*?\)/)
content_type
end end
end end
......
...@@ -23,6 +23,8 @@ class UpfileTest < Test::Unit::TestCase ...@@ -23,6 +23,8 @@ class UpfileTest < Test::Unit::TestCase
assert_equal content_type, file.content_type assert_equal content_type, file.content_type
end end
end
end
should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do
file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE")) file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE"))
...@@ -31,6 +33,4 @@ class UpfileTest < Test::Unit::TestCase ...@@ -31,6 +33,4 @@ class UpfileTest < Test::Unit::TestCase
end end
assert_equal 'text/plain', file.content_type assert_equal 'text/plain', file.content_type
end end
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