Setting up bucket's name placed domain-style (bucket.s3.amazonaws.com) with Rails and Paperclip

喜你入骨 提交于 2019-12-09 02:25:56

问题


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.


回答1:


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'
)



回答2:


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
}



回答3:


If you bucket name is DNS compatible then you can create url .s3.amazonaws.com/object....

but if it is not DNS compatible then you can not create as you want.

Thanks



来源:https://stackoverflow.com/questions/11094761/setting-up-buckets-name-placed-domain-style-bucket-s3-amazonaws-com-with-rail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!