Commit ae97ec66 by Mike Mondragon Committed by Jon Yurek

Determine content_type with file command's --mime-type when content_type is not…

Determine content_type with file command's --mime-type when content_type is not found in the default cases.
(cherry picked from commit 2ca52df1)
parent 51637fe9
......@@ -15,7 +15,8 @@ module Paperclip
when %r"html?" then "text/html"
when "js" then "application/js"
when "csv", "xml", "css" then "text/#{type}"
else "application/x-#{type}"
else
Paperclip.run("file", "--mime-type #{self.path}").split(':').last.strip rescue "application/x-#{type}"
end
end
......
......@@ -23,6 +23,14 @@ class UpfileTest < Test::Unit::TestCase
assert_equal content_type, file.content_type
end
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"))
class << file
include Paperclip::Upfile
end
assert_equal 'text/plain', file.content_type
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