carrierwave

https://github.com/jnicklas/carrierwave

Ruby

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks

CarrierWave::Uploader::ExtensionWhitelist#extension_whitelist

Override this method in your uploader to provide a white list of extensions which
are allowed to be uploaded. Compares the file's extension case insensitive.
Furthermore, not only strings but Regexp are allowed as well.

When using a Regexp in the white list, `\A` and `\z` are automatically added to
the Regexp expression, also case insensitive.

=== Returns

[NilClass, String, Regexp, Array[String, Regexp]] a white list of extensions which are allowed to be uploaded

=== Examples

    def extension_whitelist
      %w(jpg jpeg gif png)
    end

Basically the same, but using a Regexp:

    def extension_whitelist
      [/jpe?g/, 'gif', 'png']
    end

Source | Google | Stack overflow

Edit

git clone [email protected]:jnicklas/carrierwave.git

cd carrierwave

open lib/carrierwave/uploader/extension_whitelist.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-CarrierWave--Uploader--ExtensionWhitelist-extension_whitelist-for-pr


# Commit to git

git add lib/carrierwave/uploader/extension_whitelist.rbgit commit -m "better docs for CarrierWave::Uploader::ExtensionWhitelist#extension_whitelist"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-CarrierWave--Uploader--ExtensionWhitelist-extension_whitelist-for-pr

hub pull-request


# Celebrate!