0

如何让我的 Rails + Carrierwave + S3 通过 https 提供图像?

现在图片来自:

http://distilleryimage1.s3.amazonaws.com/f5314e1c866911e181b812314804a181_7.jpg

我希望它来自:

https://distilleryimage1.s3.amazonaws.com/f5314e1c866911e181b812314804a181_7.jpg

编辑

事实证明,图像是从任意数量的主机提供的:

distilleryimage11.s3, distillery.s3, 等等...

有没有办法只设置协议?

这是我的初始化程序:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => CONFIG['s3-key'],
    :aws_secret_access_key  => CONFIG['s3-secret'],
    :region                 => 'us-east-1'
  }
  config.fog_directory  = 'my_dir'
  # config.fog_host       = 'https://distilleryimage1.s3.amazonaws.com' # optional, defaults to nil
end
4

2 回答 2

3

请注意,对于 Carrierwave 0.7,它是 config.asset_host

如果你使用 .fog_host 你会得到:

config/initializers/carrierwave.rb:12:in block in <top (required)>': undefined methodfog_host=' for CarrierWave::Uploader::Base:Class (NoMethodError)

如未定义方法`fog_host='中所述

HTH 未来的读者:)

于 2012-10-29T05:48:57.373 回答
1

如果您将 Fog 与 CarrierWave 一起使用,则自述文件中的文档说您可以设置该fog_host选项:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',       # required
    :aws_access_key_id      => 'xxx',       # required
    :aws_secret_access_key  => 'yyy',       # required
    :region                 => 'eu-west-1'  # optional, defaults to 'us-east-1'
  }
  config.fog_directory  = 'name_of_directory'                     # required
  config.fog_host       = 'https://assets.example.com'            # optional, defaults to nil
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end

在您的情况下,使用config.fog_host = https://distilleryimage1.s3.amazonaws.com.

于 2012-05-27T22:29:52.040 回答