Class: Decidim::ApplicationUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
app/uploaders/decidim/application_uploader.rb

Overview

This class deals with uploading files to Decidim. It is intended to just hold the uploads configuration, so you should inherit from this class and then tweak any configuration you need.

Instance Method Summary collapse

Instance Method Details

#downloaderObject

We overwrite the downloader to be able to fetch some elements from URL.



40
41
42
# File 'app/uploaders/decidim/application_uploader.rb', line 40

def downloader
  Decidim::Downloader
end

#manipulate!Object

When the uploaded content can’t be processed, we want to make sure not to expose internal tools errors to the users. We’ll show a generic error instead.



25
26
27
28
29
30
# File 'app/uploaders/decidim/application_uploader.rb', line 25

def manipulate!
  super
rescue CarrierWave::ProcessingError => e
  Rails.logger.error(e)
  raise CarrierWave::ProcessingError, I18n.t("carrierwave.errors.general")
end

#providerObject

As of Carrierwave 2.0 fog_provider method has been deprecated, and is throwing RuntimeError RuntimeError: Carrierwave fog_provider not supported: DEPRECATION WARNING: #fog_provider is deprecated… We are attempting to fetch the provider from credentials, if not we consider to be file



35
36
37
# File 'app/uploaders/decidim/application_uploader.rb', line 35

def provider
  fog_credentials.fetch(:provider, "file").downcase
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:



14
15
16
17
18
19
20
# File 'app/uploaders/decidim/application_uploader.rb', line 14

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

  return File.join(Decidim.base_uploads_path, default_path) if Decidim.base_uploads_path.present?

  default_path
end