加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 麻烦在Rails 3 Refinery CMS App中设置s3

发布时间:2020-12-17 03:00:12 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的炼油厂cms图像存储到亚马逊s3,我正在遵循本指南: http://refinerycms.com/guides/how-to-use-amazon-s3-for-storage 但我在这里被阻止了: There are a number of ways to set these with your credentials,including unix variables or se
我正在尝试将我的炼油厂cms图像存储到亚马逊s3,我正在遵循本指南:

http://refinerycms.com/guides/how-to-use-amazon-s3-for-storage

但我在这里被阻止了:

There are a number of ways to set
these with your credentials,including
unix variables or settings them
manually through Ruby using ENV.

如何定义这些凭据.我是否应该这样:S3_KEY =>
我的environments.rb文件中的“my_key”?我尝试过这个并没有用.
我也试过这个:

AWS::S3::Base.establish_connection!(
 :access_key_id     => ENV['S3_KEY'] || 'key_goes_here',:secret_access_key => ENV['S3_SECRET'] || 's3_secret_key_here',)

无法弄清楚如何做到这一点.任何想法都非常感谢.

解决方法

最安全的方法是将它们指定为环境变量,因此它们不包含在源代码中.如果您是唯一有权访问源的人,那么按照您的描述指定它们应该有效.

您可以在?/ .bashrc中指定它们

export S3_KEY=mykey
export S3_SECRET=mysecret

或者,如果您只是在本地进行测试,则可以将它们添加到rails命令中.

$S3_KEY=mykey S3_SECRET=mysecret rails server

如果您不想/不能使用环境变量,另一种方法是使用initializer to load credentials from a yml file:config / initializers / s3_credentials.rb

# Load AWS::S3 configuration values
#
S3_CREDENTIALS = 
    YAML.load_file(File.join(Rails.root,'config/s3_credentials.yml'))[Rails.env]

# Set the AWS::S3 configuration
#
AWS::S3::Base.establish_connection! S3_CREDENTIALS['connection']

配置/ s3_credentials.yml

development: &defaults
connection:
    :access_key_id: AAAAAA_your-key-here
    :secret_access_key: 4rpsi235js_your-secret-here
    :use_ssl: true
    bucket: project-development
    acl: public-read

production:
    <<: *defaults
    bucket: project

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读