我有S3存储桶(名为' img.example.com')并且想要生成带有自定义主机名的S3过期网址以用于回形针附件。 代码:
模型:
#app/models/my_model.rb
...
has_attached_file :attachment, s3_url_options: { endpoint: 'img.example.com' }
...
配置:
#config/initializers/paperclip.rb
...
Paperclip::Attachment.default_options[:s3_host_alias] = 'img.example.com'
...
#config/environments/development.rb
...
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => 'img.example.com',
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},
:s3_permissions => :private
}
...
#expiring_url会生成这个:" http://img.example.com/ [bucket name] / [path]?[params]"
但是我想要它生成这样的网址:" http://img.example.com/ [路径]?[params]"
rails 4.1 回形针4.1.1 aws-sdk 1.11.1
答案 0 :(得分:0)
您需要在:url
中定义config.paperclip_defaults
。默认情况下,url将使用包含存储桶的":s3_path_url"
。即<protocol>//<host_name>/<bucket>/<path>
config.paperclip_defaults = {
...
:url => ":s3_alias_url"
...
}
这将生成格式<protocol>//<host_alias>/<path>
。