Module: CarrierWave::Uploader::Download

Extended by:
ActiveSupport::Concern
Includes:
Cache, Callbacks, Configuration
Included in:
Base
Defined in:
lib/carrierwave/uploader/download.rb

Defined Under Namespace

Classes: RemoteFile

Instance Method Summary collapse

Methods included from Cache

#cache!, #cache_name, #cache_stored_file!, #cached?, #retrieve_from_cache!

Methods included from Callbacks

#with_callbacks

Instance Method Details

#download!(uri) ⇒ Object

Caches the file by downloading it from the given URL.

Parameters

url (String)

The URL where the remote file is stored



53
54
55
56
57
58
59
60
# File 'lib/carrierwave/uploader/download.rb', line 53

def download!(uri)
  unless uri.blank?
    processed_uri = process_uri(uri)
    file = RemoteFile.new(processed_uri)
    raise CarrierWave::DownloadError, "trying to download a file which is not served over HTTP" unless file.http?
    cache!(file)
  end
end

#process_uri(uri) ⇒ Object

Processes the given URL by parsing and escaping it. Public to allow overriding.

Parameters

url (String)

The URL where the remote file is stored



69
70
71
# File 'lib/carrierwave/uploader/download.rb', line 69

def process_uri(uri)
  URI.parse(URI.escape(URI.unescape(uri)))
end