Sha256: e67aeb08e8ed892b2051ab6a9058587fd488ed34cf85dc2d811567bbde8c7b76

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

# encoding: utf-8
class ContentBuilderImageUploader < CarrierWave::Uploader::Base
  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  if Rails.env.development? || Rails.env.test?
    storage :file
  else
    storage :sftp
  end
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process scale: [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  # Use quality to compress the image
  version :left_or_right do
    process resize_to_fit: [640, 360]
    process quality: 80
  end

  version :center do
    process resize_to_fit: [1280, 720]
    process quality: 80
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_whitelist
    %w(jpg jpeg gif png)
  end

  # Mitigate CVE-2016-3714
  def content_type_whitelist
    [/image\//]
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_admin_content_builder_rails_6-1.2.0 lib/generators/templates/content_builder_image_uploader.rb
rails_admin_content_builder_rails_6-1.1.0 lib/rails_admin_content_builder_rails_6/generators/templates/content_builder_image_uploader.rb