与Rails和回形针设置桶的名字放在域样式(bucket.s3.amazonaws.com)(Set

2019-06-25 14:04发布

有关网址选项回形针文档:

你可以选择让斗的名字放在域样式(bucket.s3.amazonaws.com)或路径式(s3.amazonaws.com/bucket)。

如何将看起来像设置确实让斗的名字放在域样式? 我不能强迫回形针生成URL bucket.s3.amazonaws.com的s3.amazonaws.com/bucket代替等。

Answer 1:

只要设定这样的:

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'

或者是这样的:

Paperclip::Attachment.default_options.merge!(
  :url => ':s3_domain_url'
)


Answer 2:

添加:url:pathPaperclip默认选项在application.rbenvironment.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
}


Answer 3:

如果你斗的名字是DNS兼容,那么你可以创建网址.s3.amazonaws.com /对象....

但如果是不兼容的DNS,那么你不能只要你想创建。

谢谢



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