Class: FeaturedContentImageUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
lib/generators/templates/featured_content_image_uploader.rb

Instance Method Summary collapse

Instance Method Details

#content_type_whitelistObject

Mitigate CVE-2016-3714



51
52
53
# File 'lib/generators/templates/featured_content_image_uploader.rb', line 51

def content_type_whitelist
  [/image\//]
end

#extension_whitelistObject

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:



46
47
48
# File 'lib/generators/templates/featured_content_image_uploader.rb', line 46

def extension_whitelist
  %w(jpg jpeg gif png)
end

#filenameObject

Override the filename of the uploaded files: Avoid using model.id or version_name here, see uploader/store.rb for details.



57
58
59
60
61
62
63
# File 'lib/generators/templates/featured_content_image_uploader.rb', line 57

def filename
  if original_filename
    image_format = original_filename.match(/\.([^.]*)$/).to_a.first
    image_name = original_filename.gsub(/\.([^.]*)$/, "").parameterize
    return "#{image_name}#{image_format}"
  end
end

#store_dirObject

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:



18
19
20
# File 'lib/generators/templates/featured_content_image_uploader.rb', line 18

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end