Commit 04af5821 by Zach Millman Committed by Jon Yurek

Try matching uploaded file type before defaulting to first official one

and memoize type_from_file_command
parent dbb7e043
......@@ -44,12 +44,13 @@ module Paperclip
end
def best_type_match
types_matching_file = possible_types.select {|type| type.content_type == type_from_file_command}
official_types = possible_types.reject {|type| type.content_type.match(/\/x-/) }
(official_types.first || possible_types.first).content_type
(types_matching_file.first || official_types.first || possible_types.first).content_type
end
def type_from_file_command
FileCommandContentTypeDetector.new(@filename).detect
@type_from_file_command ||= FileCommandContentTypeDetector.new(@filename).detect
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