阅读背景:

使用Rails和Paperclip设置存储桶名称的域名样式(bucket.s3.amazonaws.com)

来源:互联网 

Paperclip doc about url options:

关于网址选项的Paperclip doc:

You can choose to have the bucket's name placed domain-style (bucket.s3.amazonaws.com) or path-style (s3.amazonaws.com/bucket).

您可以选择将存储桶的名称放置为域样式(bucket.s3.amazonaws.com)或路径样式(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.

看起来设置实际上将桶的名称放置为域式?我不能强制回形针生成像bucket.s3.amazonaws.com而不是s3.amazonaws.com/bucket这样的网址。

3 个解决方案

#1


14  

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


4  

Add :url and :path to the Paperclip default options in your application.rb or environment.rb

添加:url和:application.rb或environment.rb中Paperclip默认选项的路径

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


1  

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

如果您的存储桶名称与DNS兼容,那么您可以创建网址.s3.amazonaws.com / object ....

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

但如果它不兼容DNS,则无法按需创建。

Thanks

谢谢


分享到: