Module: WebpackerUploader::Mime

Defined in:
lib/webpacker_uploader/mime.rb

Class Method Summary collapse

Class Method Details

.mime_type(file_path) ⇒ String

Returns the mime type for the given file in the filesystem. If it's unable to detect the mime type, it returns +application/octet-stream+ as a fallback.

Parameters:

  • file_path (String)

    A file path in the local filesystem.

Returns:

  • (String)

    The file mime type.



12
13
14
15
# File 'lib/webpacker_uploader/mime.rb', line 12

def mime_type(file_path)
  fallback = MIME::Types.type_for(file_path).first&.content_type || "application/octet-stream"
  Rack::Mime.mime_type(File.extname(file_path), fallback)
end