如何解决"缺少凭证"用回形针和S3存储在轨道3 [英] How to resolve "Missing Credentials" with Paperclip and s3 storage in rails 3

查看:187
本文介绍了如何解决"缺少凭证"用回形针和S3存储在轨道3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pretty的简单的模型和附件

I have a pretty straightforward model and attachment

has_attached_file :upload,
    :storage => :s3,
       :bucket => 'bestofbauer',
       :s3_credentials => {
         :access_key_id => ENV['MyAccessKEY'],
         :secret_access_key => ENV['MySecretKey']
       }

我有一个桶的设置与S3称为bestofbauer。

I have a bucket setup with s3 called bestofbauer.

我知道我可以重构凭证到初始化,但我还没有得到这对保存附件还没有,所以我并不担心。

I know I could refactor the credentials into an initializer but I haven't gotten this to save an attachment yet so I haven't worried about it.

当我运行保存的对象及其attachement我得到:

When I run the save for the object and its attachement I get:

RuntimeError in RecommendationsController#create

Missing credentials

我已经倒了过来:<一href="http://stackoverflow.com/questions/9409725/credentials-missing-when-uploading-photos-with-paperclip-and-amazon-s3">Credentials用回形针和亚马逊S3 上传照片时,但没有解决我的问题,缺少的。

I have poured over: Credentials missing when uploading photos with Paperclip and Amazon s3 but that didn't resolve my issue.

我用下面的宝石:

gem "paperclip"
gem "sws-sdk"
gem 'aws-s3'

任何其他的想法?

Any other ideas?

推荐答案

您需要设置环境变量。这里有两种不同的方式来做到这一点:

You need to set your environment variables. Here's two different ways to do it:

  1. 运行每次导轨服务器或访问你需要包括你的钥匙您的S3帐户中的任何其他命令:

  1. Every time you run rails server or any other command that accesses your S3 account you need to include your keys:

$ MyAccessKEY=ACCESS_KEY MySecretKEY=SECRET_KEY rails server

  • 我在你使用bash这样修改〜/ .bash_rc 〜/ .bash_profile中来设置环境变量

  • I'm assuming you're using bash so edit your ~/.bash_rc or ~/.bash_profile to set your environment variables

    export MyAccessKEY=ACCESS_KEY
    export MySecretKEY=SECRET_KEY
    

    然后打开一个新的终端窗口,并仔细检查,他们正在设置

    Then open a new terminal window and double-check that they're set

    $ echo $MyAccessKey
    > ACCESS KEY PRINTS OUT HERE
    

  • 如果您要部署到Heroku的话你要提供你的环境变量有作为:

    If you're deploying to Heroku then you'll want to provide your environment variables there as well:

    $ heroku config:add MyAccessKEY=ACCESS_KEY MySecretKEY=SECRET_KEY
    

    您可以查看您的Heroku的配置:

    You can review your Heroku config:

    $ heroku config
    

    它会列出所有你该应用程序的配置变量。

    It will list out all of the config variables you have for that app.

    您可能会想要把你的S3存储的名字在ENV设置,以及使你在本地测试时,不要弄乱你的水桶。

    You'll probably want to put your S3 bucket name in an ENV setting as well so you don't mess up your bucket when testing locally.

    这篇关于如何解决&QUOT;缺少凭证&QUOT;用回形针和S3存储在轨道3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆