Project

mime-typer

0.0
No commit activity in last 3 years
No release in over 3 years
A gem to detect mime type of a file, using libmagic.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.3
~> 10.3
 Project Readme

MIME Typer

A simple library to detect mime type of a file, using libmagic

Installation:

Add this line in your Gemfile

gem 'mime-typer'

Run tests:

bundle exec rake

Requirements:

It requires both awk and file to be installed and available in your PATH. Installation will fail if you miss them.

How to use:

MIME::Typer.detect('path/to/my/image.jpg') # => 'image/jpg'

You can also pass an already opened file:

myfile = File.open('path/to/my/image.jpg')
MIME::Typer.detect(myfile) # => 'image/jpg'

If you want to detect the MIME Type of a remote file you can use the remote method

MIME::Typer.remote('http://www.yoursite.com/image.png') # => 'image/png'

This will load only the first part of the file, so it's quite fast also with large remote files.

Warning this feature is quite experimental!