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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request