Class: ContentBuilderImageUploader

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

Instance Method Summary collapse

Instance Method Details

#content_type_whitelistObject

Mitigate CVE-2016-3714



55
56
57
# File 'lib/generators/templates/content_builder_image_uploader.rb', line 55

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:



50
51
52
# File 'lib/generators/templates/content_builder_image_uploader.rb', line 50

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.



61
62
63
64
65
66
67
# File 'lib/generators/templates/content_builder_image_uploader.rb', line 61

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:



17
18
19
# File 'lib/generators/templates/content_builder_image_uploader.rb', line 17

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