Paperclip doc about url options:
You can choose to have the bucket's name placed domain-style (bucket.s3.amazonaws.com) or path-style (s3.amazonaws.com/bucket).
How would look like the setup to actually have bucket's name placed domain-style? I can't force paperclip to generate urls like bucket.s3.amazonaws.com instead of s3.amazonaws.com/bucket.
Currently, Amazon S3 supports both virtual-hosted–style and path-style URL access in all AWS Regions.
The following rules apply for naming buckets in Amazon S3: Bucket names must be between 3 (min) and 63 (max) characters long. Bucket names can consist only of lowercase letters, numbers, dots (.), and hyphens (-). Bucket names must begin and end with a letter or number.
There are two parts to masking your S3 url, the first is creating and naming a bucket in S3 to match the subdomain, the second is creating the subdomain and pointing it to the S3 bucket url.
Create a new bucket in another region. Note that you can not have the same bucket name as your current one because bucket names must be unique. Copy the contents of the current bucket to the new bucket created in the region you prefer. Once copied, delete the old bucket.
Just set it like this:
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Or like this:
Paperclip::Attachment.default_options.merge!(
:url => ':s3_domain_url'
)
Add :url
and :path
to the Paperclip
default options in your application.rb
or environment.rb
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV['MY_S3_BUCKET_NAME'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
},
url: ':s3_domain_url', # ADD THIS
path: '/:class/:attachment/:id_partition/:style/:filename' # ADD THIS
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With