Sha256: f072ec4ec4e4096ddeb2fdc394f0b13665908c6c03b6e08b8cb5ce40ea557210
Contents?: true
Size: 755 Bytes
Versions: 18
Compression:
Stored size: 755 Bytes
Contents
module Paperclip class FileCommandContentTypeDetector SENSIBLE_DEFAULT = "application/octet-stream" def initialize(filename) @filename = filename end def detect type_from_file_command end private def type_from_file_command # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. type = begin Paperclip.run("file", "-b --mime :file", file: @filename) rescue Cocaine::CommandLineError => e Paperclip.log("Error while determining content type: #{e}") SENSIBLE_DEFAULT end if type.nil? || type.match(/\(.*?\)/) type = SENSIBLE_DEFAULT end type.split(/[:;\s]+/)[0] end end end
Version data entries
18 entries across 18 versions & 5 rubygems