Commit 02d99ec3 by Prem Sichanugrist

Merge pull request #829 from kir/master

Fix problem with incorrect content_type from `file` command
parents 05a23718 3e98fc2e
...@@ -69,7 +69,7 @@ module Paperclip ...@@ -69,7 +69,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 :file", :file => self.path).split(/[:;]\s+/)[0] 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
......
...@@ -20,6 +20,13 @@ class FileAdapterTest < Test::Unit::TestCase ...@@ -20,6 +20,13 @@ class FileAdapterTest < Test::Unit::TestCase
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
should "provide correct mime-type for empty file" do
@subject = Paperclip.io_adapters.for(Tempfile.new("file_adapter_test"))
# Content type contained '\n' at the end, for an empty file, on my Mac
assert_equal "application/x-empty", @subject.content_type
end
should "get the file's size" do should "get the file's size" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
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