Class: FeaturedContentImageUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- FeaturedContentImageUploader
- Includes:
- CarrierWave::MiniMagick
- Defined in:
- lib/generators/templates/featured_content_image_uploader.rb
Instance Method Summary collapse
-
#content_type_whitelist ⇒ Object
Mitigate CVE-2016-3714.
-
#extension_whitelist ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
-
#filename ⇒ Object
Override the filename of the uploaded files: Avoid using model.id or version_name here, see uploader/store.rb for details.
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
Instance Method Details
#content_type_whitelist ⇒ Object
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_whitelist ⇒ Object
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 |
#filename ⇒ Object
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_dir ⇒ Object
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 |