https://github.com/progm/mime-typer
A gem to detect mime type of a file, using libmagic.
https://github.com/progm/mime-typer
Last synced: 8 months ago
JSON representation
A gem to detect mime type of a file, using libmagic.
- Host: GitHub
- URL: https://github.com/progm/mime-typer
- Owner: ProGM
- License: mit
- Created: 2014-08-01T07:00:51.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-06T08:51:02.000Z (almost 12 years ago)
- Last Synced: 2025-06-28T15:06:44.296Z (about 1 year ago)
- Language: Ruby
- Size: 230 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this 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](http://en.wikipedia.org/wiki/AWK) and [file](http://en.wikipedia.org/wiki/File_(command)) 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!