使用 fog.yml 为 S3 存储桶配置 Rails 3
Configure Rails 3 for S3 bucket using fog.yml
我有这个 Rails 3.2 应用程序从我公司以前的自由职业者那里传递过来的。我想知道如何将这个现有的 S3 存储桶配置到我的新 EC2 实例。
使用 fog gem 和 carrierwave gem.
在 fog.yml 中配置对 AWS 的访问
我在这个 fog.yml 文件中遗漏了什么
Fog.credentials_path = Rails.root.join('config/fog.yml')
CarrierWave.configure do |config|
config.fog_credentials = {
}
config.fog_directory = "directory-name"
config.fog_public = false
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
我会看看这些例子:
http://fog.io/about/getting_started.html
看起来格式基本是:
development:
aws_access_key_id: 'XXXXXXXXXXXXXXX'
aws_secret_access_key: 'XXXXXXXXXXXXXXX'
provider: 'AWS'
test:
aws_access_key_id: 'XXXXXXXXXXXXXXX'
aws_secret_access_key: 'XXXXXXXXXXXXXXX'
provider: 'AWS'
# set these environment variables on your prod server
production:
aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
provider: 'AWS'
确保使用空格而不是制表符,因为它是 YAML 文件。
#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'aws_key',
:aws_secret_access_key => 'aws_secret'
}
config.fog_directory = 'bucket1'
config.fog_host = 'https://s3.amazonaws.com'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
#app/uploader/image_uploader.rb
def store_dir
"images/#{model.class.to_s.underscore}"
end
#app/views/pictures/show.html.erb
<%= image_tag @picture.image_url if @picture.image? %>`enter code here`
我有这个 Rails 3.2 应用程序从我公司以前的自由职业者那里传递过来的。我想知道如何将这个现有的 S3 存储桶配置到我的新 EC2 实例。
使用 fog gem 和 carrierwave gem.
我在这个 fog.yml 文件中遗漏了什么
Fog.credentials_path = Rails.root.join('config/fog.yml')
CarrierWave.configure do |config|
config.fog_credentials = {
}
config.fog_directory = "directory-name"
config.fog_public = false
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
我会看看这些例子:
http://fog.io/about/getting_started.html
看起来格式基本是:
development:
aws_access_key_id: 'XXXXXXXXXXXXXXX'
aws_secret_access_key: 'XXXXXXXXXXXXXXX'
provider: 'AWS'
test:
aws_access_key_id: 'XXXXXXXXXXXXXXX'
aws_secret_access_key: 'XXXXXXXXXXXXXXX'
provider: 'AWS'
# set these environment variables on your prod server
production:
aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
provider: 'AWS'
确保使用空格而不是制表符,因为它是 YAML 文件。
#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'aws_key',
:aws_secret_access_key => 'aws_secret'
}
config.fog_directory = 'bucket1'
config.fog_host = 'https://s3.amazonaws.com'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
#app/uploader/image_uploader.rb
def store_dir
"images/#{model.class.to_s.underscore}"
end
#app/views/pictures/show.html.erb
<%= image_tag @picture.image_url if @picture.image? %>`enter code here`