lib/carrierwave/storage/fog.rb in carrierwave-0.8.0 vs lib/carrierwave/storage/fog.rb in carrierwave-0.9.0

- old
+ new

@@ -17,10 +17,11 @@ # # [:fog_attributes] (optional) additional attributes to set on files # [:fog_public] (optional) public readability, defaults to true # [:fog_authenticated_url_expiration] (optional) time (in seconds) that authenticated urls # will be valid, when fog_public is false and provider is AWS or Google, defaults to 600 + # [:fog_use_ssl_for_aws] (optional) #public_url will use https for the AWS generated URL] # # # AWS credentials contain the following keys: # # [:aws_access_key_id] @@ -101,10 +102,11 @@ self.class.connection_cache[credentials] ||= ::Fog::Storage.new(options) end end class File + include CarrierWave::Utilities::Uri ## # Current local path to file # # === Returns @@ -273,34 +275,36 @@ # [String] public url # or # [NilClass] no public url available # def public_url + encoded_path = encode_path(path) if host = @uploader.asset_host if host.respond_to? :call - "#{host.call(self)}/#{path}" + "#{host.call(self)}/#{encoded_path}" else - "#{host}/#{path}" + "#{host}/#{encoded_path}" end else # AWS/Google optimized for speed over correctness case @uploader.fog_credentials[:provider] when 'AWS' # check if some endpoint is set in fog_credentials if @uploader.fog_credentials.has_key?(:endpoint) - "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{path}" + "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{encoded_path}" else + protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http" # if directory is a valid subdomain, use that style for access if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/ - "https://#{@uploader.fog_directory}.s3.amazonaws.com/#{path}" + "#{protocol}://#{@uploader.fog_directory}.s3.amazonaws.com/#{encoded_path}" else # directory is not a valid subdomain, so use path style for access - "https://s3.amazonaws.com/#{@uploader.fog_directory}/#{path}" + "#{protocol}://s3.amazonaws.com/#{@uploader.fog_directory}/#{encoded_path}" end end when 'Google' - "https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{path}" + "https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{encoded_path}" else # avoid a get by just using local reference directory.files.new(:key => path).public_url end end @@ -332,10 +336,10 @@ # or # [NilClass] no file name available # def filename(options = {}) if file_url = url(options) - file_url.gsub(/.*\/(.*?$)/, '\1') + URI.decode(file_url).gsub(/.*\/(.*?$)/, '\1') end end private