How to resolve “Missing Credentials” with Paperclip and s3 storage in rails 3

后端 未结 1 1573
無奈伤痛
無奈伤痛 2020-12-29 17:36

I have a pretty straightforward model and attachment

has_attached_file :upload,
    :storage => :s3,
       :bucket => \'bestofbauer\',
       :s3_cred         


        
相关标签:
1条回答
  • 2020-12-29 18:35

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

    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
      
    2. 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
      

    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
    

    You can review your Heroku config:

    $ heroku config
    

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

    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.

    0 讨论(0)
提交回复
热议问题