No commit activity in last 3 years
No release in over 3 years
Real mime-types for carrierwave
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.10.0
~> 0.3.0
 Project Readme

CarrierWave::MimetypeMagic

Gem Version

By default, carrierwave uses the uploaded file's extension to guess the content type. Sometimes you'd prefer to actually look at the file and set the content type based on that, so users can't upload php files as i_am_lying.jpg and have the server try to process them as images.

This gem checks the file when it's first uploaded, sets the content type as appropriate and, if the filename's original extension doesn't match the content type, renames it so it does.

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-mimetype-magic'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install carrierwave-mimetype-magic

Usage

Just include the module in your uploader:

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MimetypeMagic
end

And now uploaded files' content_type will be set appropriately, and uploads will automatically be renamed before being passed on to the processors. Given a jpeg file named test_1.pdf, the file will be renamed test_1.jpg before being passed off to normal carrierwave processing.

History

Originally based on the carrierwave-mymetype-fu (that based on carrierwave-magic) gem, but using mimemagic rather than MimetypeFu, that works incorrect with MS files.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request