1) I have a bucket called `
assets.foo.com` on S3
2) I have added a CNAME on my domain to point to S3.
assets.foo.com ->
s3.amazonaws.com
The CNAME is propagated as I am able to access my bucket files using
assets.foo.com domain name.
3) Model code:
has_attached_file :report,
:storage => :s3,
:s3_credentials => {
:access_key_id => "xxxx",
:secret_access_key => "yyyy"},
:s3_permissions => 'private',
:s3_protocol => 'http',
:s3_host_alias => "
assets.foo.com",
:url => ":s3_alias_url",
:bucket => "
assets.foo.com",
:path =>
":class/:attachment/:id_partition_:style.:extension"
I get the expected URL when I access an existing resource and I am
able to access the file using the URL.
s.report.url
#
http://assets.foo.com/study/report/..../abc.pdf
I get an error when try to generate an expiring URL
s.report.expiring_url
AWS::S3::CurrentBucketNotSpecified: No bucket name can be inferred
from your current connection's address (`
s3.amazonaws.com')
from C:/Ruby187/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/
base.rb:107:in `current_bucket'
from C:/Ruby187/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/
base.rb:179:in `bucket_name'
from C:/Ruby187/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/
object.rb:300:in `path!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/
object.rb:291:in `url_for'
from C:/Ruby187/lib/ruby/gems/1.8/gems/paperclip-2.3.11/lib/
paperclip/storage/s3.rb:98:in `expiring_url'
from (irb):4
According to the user manual one bucket name is inferred if
`:s3_host_alias` specified and `:url` is set to `":s3_alias_url"`.
I was able to work around the problem by adding the bucket
configuration, i.e.
has_attached_file :report,
:storage => :s3,
:s3_credentials => {
:access_key_id => "xxxx",
:secret_access_key => "yyyy"},
:s3_permissions => 'private',
:s3_protocol => 'http',
:s3_host_alias => "
assets.foo.com",
:url => ":s3_alias_url",
:bucket => "
assets.foo.com",
:path =>
":class/:attachment/:id_partition_:style.:extension"
When I add the bucket configuration, the `expiring_url` method ignores
the custom CNAME alias.
s.report.expiring_url
#
http://s3.amazon.com/assets.foo.com/study/report/..../abc.pdf
Interestingly, the `url` function generates the expected url even when
the `bucket` configuration is present.
s.report.url
#
http://assets.foo.com/study/report/..../abc.pdf