Module: CarrierWave::Uploader::ExtensionWhitelist

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/carrierwave/uploader/extension_whitelist.rb

Instance Method Summary collapse

Instance Method Details

#extension_allowlistObject

Override this method in your uploader to provide an allowlist 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 allowlist, ‘A` and `z` are automatically added to the Regexp expression, also case insensitive.

Returns

NilClass, String, Regexp, Array[String, Regexp]

an allowlist of extensions which are allowed to be uploaded

Examples

def extension_allowlist
  %w(jpg jpeg gif png)
end

Basically the same, but using a Regexp:

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


34
35
36
37
38
39
40
# File 'lib/carrierwave/uploader/extension_whitelist.rb', line 34

def extension_allowlist
  if respond_to?(:extension_whitelist)
    ActiveSupport::Deprecation.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
    @extension_whitelist_warned = true
    extension_whitelist
  end
end