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

Runtime

 Project Readme

CarrierWave::MimetypeFu

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-fu'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install carrierwave-mimetype-fu

Usage

Just include the module in your uploader:

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MimetypeFu
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-magic gem, but using MimetypeFu rather than requiring installation of libmagic. Shifted to a different approach in order to check the content type early enough to automatically rename the upload with the proper extension before the processors go to work.

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