Permalink
Browse files

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

…ype is not found in the default cases.
  • Loading branch information...
1 parent 91b30cd commit 2ca52df1aa45a8a9cb3d086a6be77168b7f5be52 @monde monde committed Dec 27, 2009
Showing with 10 additions and 1 deletion.
  1. +2 −1 lib/paperclip/upfile.rb
  2. +8 −0 test/upfile_test.rb
View
3 lib/paperclip/upfile.rb
@@ -15,7 +15,8 @@ def content_type
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
View
8 test/upfile_test.rb
@@ -23,6 +23,14 @@ class << file
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

0 comments on commit 2ca52df

Please sign in to comment.