diff --git a/lib/paperclip/storage.rb b/lib/paperclip/storage.rb index a2b93b9..65a574b 100644 --- a/lib/paperclip/storage.rb +++ b/lib/paperclip/storage.rb @@ -98,13 +98,19 @@ module Paperclip require 'right_aws' base.instance_eval do @bucket = @options[:bucket] + @url_format = @options[:url_format] || :path @s3_credentials = parse_credentials(@options[:s3_credentials]) @s3_options = @options[:s3_options] || {} @s3_permissions = @options[:s3_permissions] || 'public-read' @url = ":s3_url" end base.class.interpolations[:s3_url] = lambda do |attachment, style| - "https://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}" + if attachment.use_subdomain_url_format? + url = "https://#{attachment.bucket_name}.amazonaws.com" + else + url = "https://s3.amazonaws.com/#{attachment.bucket_name}" + end + url += "/#{attachment.path(style).gsub(%r{^/}, "")}" end ActiveRecord::Base.logger.info("[paperclip] S3 Storage Initalized.") end @@ -122,6 +128,10 @@ module Paperclip def bucket_name @bucket end + + def use_subdomain_url_format? + @url_format == :subdomain + end def parse_credentials creds creds = find_credentials(creds).stringify_keys