Module: Carrierwave::Base64::Adapter

Defined in:
lib/carrierwave/base64/adapter.rb

Overview

Module with .mount_base64_uploader method, that is mixed in to ActiveRecord::Base or Mongoid::Document::ClassMethods

Instance Method Summary collapse

Instance Method Details

#mount_base64_uploader(attribute, uploader_class, options = {}) ⇒ Symbol

Mounts the carrierwave uploader that can accept a base64 encoded string as input. It also accepts regular file uploads.

Examples:

Mount the uploader and specify the file name

mount_base64_uploader :image, ImageUploader,
  file_name: -> (u) { u.username }

Parameters:

  • attribute (Symbol)

    the attribute to mount this uploader on

  • uploader_class (Carrierwave::Uploader)

    the uploader class to mount

  • options (Hash{Symbol => Object}) (defaults to: {})

    a set of options

Options Hash (options):

  • :file_name (Proc)

    Proc that must return a file name without extension

Returns:

  • (Symbol)

    the defined writer method name


21
22
23
24
25
26
27
28
29
30
# File 'lib/carrierwave/base64/adapter.rb', line 21

def mount_base64_uploader(attribute, uploader_class, options = {})
  mount_uploader attribute, uploader_class, options
  options[:file_name] ||= proc { attribute }

  Carrierwave::Base64::MountingHelper.check_for_deprecations(options)

  Carrierwave::Base64::MountingHelper.define_writer(
    self, attribute, options
  )
end