Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
available s3 tokyo region
Browse files Browse the repository at this point in the history
  • Loading branch information
takuyan committed Jul 14, 2011
1 parent dcad54d commit 1c91f71
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module Storage
# to interpolate. Keys should be unique, like filenames, and despite the fact that
# S3 (strictly speaking) does not support directories, you can still use a / to
# separate parts of your file name.
# * +region+: If you are using your bucket in Tokyo region, "tokyo" write.
module S3
def self.extended base
begin
Expand All @@ -77,6 +78,7 @@ def self.extended base

base.instance_eval do
@s3_credentials = parse_credentials(@options[:s3_credentials])
@region = @options[:region] || @s3_credentials[:region]
@bucket = @options[:bucket] || @s3_credentials[:bucket]
@bucket = @bucket.call(self) if @bucket.is_a?(Proc)
@s3_options = @options[:s3_options] || {}
Expand All @@ -102,10 +104,10 @@ def self.extended base
"#{attachment.s3_protocol(style)}://#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_alias_url
Paperclip.interpolates(:s3_path_url) do |attachment, style|
"#{attachment.s3_protocol(style)}://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.s3_protocol(style)}://#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_path_url
Paperclip.interpolates(:s3_domain_url) do |attachment, style|
"#{attachment.s3_protocol(style)}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{attachment.s3_protocol(style)}://#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_domain_url
Paperclip.interpolates(:asset_host) do |attachment, style|
"#{attachment.path(style).gsub(%r{^/}, "")}"
Expand All @@ -120,6 +122,16 @@ def bucket_name
@bucket
end

def s3_host_name
case @region
when "tokyo"
AWS::S3::DEFAULT_HOST.replace "s3-ap-northeast-1.amazonaws.com"
"s3-ap-northeast-1.amazonaws.com"
else
"s3.amazonaws.com"
end
end

def set_permissions permissions
if permissions.is_a?(Hash)
permissions[:default] = permissions[:default] || :public_read
Expand Down

4 comments on commit 1c91f71

@czj
Copy link

@czj czj commented on 1c91f71 Jul 17, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice add-on but support for all S3 regions should be added :

Amazon Simple Storage Service

US Standard * s3.amazonaws.com
US-West (Northern California) Region s3-us-west-1.amazonaws.com
EU (Ireland) Region s3-eu-west-1.amazonaws.com
Asia Pacific (Singapore) Region s3-ap-southeast-1.amazonaws.com
Asia Pacific (Tokyo) Region s3-ap-northeast-1.amazonaws.com

@sikachu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we're planning to add that too. :)

@czj
Copy link

@czj czj commented on 1c91f71 Jul 17, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takuyan
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for merge ! :-)

Please sign in to comment.