Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/paperclip/content_type_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def calculated_type_matches
end

def type_from_file_contents
type_from_mime_magic || type_from_file_command
type_from_mime_magic || certificate_type || type_from_file_command
rescue Errno::ENOENT => e
Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT
Expand All @@ -75,5 +75,11 @@ def type_from_mime_magic
@type_from_mime_magic ||=
MimeMagic.by_magic(File.open(@filename)).try(:type)
end

def certificate_type
OpenSSL::X509::Certificate.new(File.read(@filename))
'application/x-x509-ca-cert'
rescue StandardError
end
end
end