No commit activity in last 3 years
No release in over 3 years
ruby-filemagic and 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
 Project Readme

CarrierWave::Magic

This allows to set file type with ruby-filemagic instead of an extension

To set correct file extension on resulting files on disk:

Add this to your uploader (or any other way)

def filename
    if original_filename.present?
        ext = MIME::Types[file.content_type].nil? ? file.extension : MIME::Types[file.content_type].first.extensions.first
        split_extension(original_filename)[0] + '.' + ext
    end
end

Idea and some of the code from this pull request: carrierwaveuploader/carrierwave#949

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-magic'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-magic

Usage

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::Magic
  process :set_magic_content_type
end

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