Class: Decidim::ImageUploader
- Inherits:
-
ApplicationUploader
- Object
- CarrierWave::Uploader::Base
- ApplicationUploader
- Decidim::ImageUploader
- Includes:
- CarrierWave::MiniMagick
- Defined in:
- app/uploaders/decidim/image_uploader.rb
Overview
This class deals with uploading hero images to ParticipatoryProcesses.
Direct Known Subclasses
AvatarUploader, BannerImageUploader, HeroImageUploader, HomepageImageUploader, OAuthApplicationLogoUploader, OfficialImageFooterUploader, OfficialImageHeaderUploader, OrganizationFaviconUploader, OrganizationLogoUploader
Instance Method Summary collapse
-
#content_type_whitelist ⇒ Object
CarrierWave automatically calls this method and validates the content type fo the temp file to match against any of these options.
-
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
- #max_image_height_or_width ⇒ Object
-
#strip ⇒ Object
Strips out all embedded information from the image.
-
#validate_dimensions ⇒ Object
A simple check to avoid DoS with maliciously crafted images, or just to avoid reckless users that upload gigapixels images.
- #validate_size ⇒ Object
Methods inherited from ApplicationUploader
Instance Method Details
#content_type_whitelist ⇒ Object
CarrierWave automatically calls this method and validates the content type fo the temp file to match against any of these options.
13 14 15 16 17 |
# File 'app/uploaders/decidim/image_uploader.rb', line 13 def content_type_whitelist [ %r{image\/} ] end |
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:
29 30 31 |
# File 'app/uploaders/decidim/image_uploader.rb', line 29 def extension_white_list %w(jpg jpeg gif png bmp ico) end |
#max_image_height_or_width ⇒ Object
51 52 53 |
# File 'app/uploaders/decidim/image_uploader.rb', line 51 def max_image_height_or_width 3840 end |
#strip ⇒ Object
Strips out all embedded information from the image
20 21 22 23 24 25 |
# File 'app/uploaders/decidim/image_uploader.rb', line 20 def strip manipulate! do |img| img.strip img end end |
#validate_dimensions ⇒ Object
A simple check to avoid DoS with maliciously crafted images, or just to avoid reckless users that upload gigapixels images.
37 38 39 40 41 42 |
# File 'app/uploaders/decidim/image_uploader.rb', line 37 def validate_dimensions manipulate! do |image| validation_error!(I18n.t("carrierwave.errors.image_too_big")) if image.dimensions.any? { |dimension| dimension > max_image_height_or_width } image end end |
#validate_size ⇒ Object
44 45 46 47 48 49 |
# File 'app/uploaders/decidim/image_uploader.rb', line 44 def validate_size manipulate! do |image| validation_error!(I18n.t("carrierwave.errors.image_too_big")) if image.size > Decidim. image end end |