lib/carrierwave/uploader/download.rb in carrierwave-0.5.0.beta2 vs lib/carrierwave/uploader/download.rb in carrierwave-0.5.0
- old
+ new
@@ -1,8 +1,8 @@
# encoding: utf-8
-require 'net/http'
+require 'open-uri'
module CarrierWave
module Uploader
module Download
extend ActiveSupport::Concern
@@ -11,11 +11,11 @@
include CarrierWave::Uploader::Configuration
include CarrierWave::Uploader::Cache
class RemoteFile
def initialize(uri)
- @uri = URI.parse(uri)
+ @uri = URI.parse(URI.escape(uri))
end
def original_filename
File.basename(@uri.path)
end
@@ -29,10 +29,14 @@
end
private
def file
- @file ||= StringIO.new(Net::HTTP.get_response(@uri).body)
+ if @file.blank?
+ @file = Kernel.open(@uri.to_s)
+ @file = @file.is_a?(String) ? StringIO.new(@file) : @file
+ end
+ @file
end
def method_missing(*args, &block)
file.send(*args, &block)
end