lib/carrierwave/uploader/download.rb in carrierwave-0.5.2 vs lib/carrierwave/uploader/download.rb in carrierwave-0.5.3
- old
+ new
@@ -11,15 +11,15 @@
include CarrierWave::Uploader::Configuration
include CarrierWave::Uploader::Cache
class RemoteFile
def initialize(uri)
- @uri = URI.parse(URI.escape(uri))
+ @uri = uri
end
def original_filename
- File.basename(@uri.path)
+ File.basename(file.base_uri.path)
end
def respond_to?(*args)
super or file.respond_to?(*args)
end
@@ -50,15 +50,26 @@
#
# [url (String)] The URL where the remote file is stored
#
def download!(uri)
unless uri.blank?
- file = RemoteFile.new(uri)
+ 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
+ ##
+ # Processes the given URL by parsing and escaping it. Public to allow overriding.
+ #
+ # === Parameters
+ #
+ # [url (String)] The URL where the remote file is stored
+ #
+ def process_uri(uri)
+ URI.parse(URI.escape(uri))
+ end
+
end # Download
end # Uploader
end # CarrierWave
-