2012-05-27 83 views
0

如何讓我的Rails + Carrierwave + S3通過https提供圖片?Carrierwave + S3:如何指定https?

眼下圖片來自:

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

我希望它來自:

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

編輯

原來的圖像從任何數量的供應的主機:

distilleryimage11.s3distillery.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 

回答

1

如果你使用霧與CarrierWave,the documentation in the readme說,你可以設置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

+0

起初,這種方法很有效,但現在我的圖像可以從任意數量的主機上得到(distilleryimage5.s3,distillery.s3等等)。有沒有辦法設置協議?在代碼中找不到它:https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/storage/fog.rb – bevanb

+1

啊,我明白了。這真有趣;根據https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/storage/fog.rb#L269-294,如果沒有設置'fog_host',它看起來應該默認使用SSL。 .. –

3

只是說明與Carrierwave 0.7是config.asset_host

如果使用.fog_host您將獲得:

配置/初始化/ carrierwave.rb:12:block in <top (required)>': undefined method fog_host =」爲CarrierWave: :上傳:: Base的:類作爲解釋(NoMethodError)

undefined method `fog_host='

HTH未來的讀者:)