2

Paperclip 非常适合我在 Heroku 上的应用程序,但我似乎无法让它在本地工作。每次我尝试做某事时,我都会得到一个“缺少必需的 :bucket 选项”......但是存储桶就在那里,它可以在 Heroku 上运行!

如果有帮助,这是我的模型:

  has_attached_file :screen_one, :styles => { :medium => "800x600>", :thumb => "110x80#" },
  :storage => :s3,
  :s3_credentials => {
    :access_key_id => ENV['accesskeyishere'],
    :bucket => ENV['sitebuilderreport'],
    :secret_access_key => ENV['secretaccesskeyishere']
  }

我已经更改了访问密钥,因为这是一个公开帖子:)

4

5 回答 5

6

I met the same problem (missing :bucket every single where). The answer below works perfectly in my case.

a. Add these to .bash_profile (Note: Fill in with your Amazon account credentials)

export AWS_ACCESS_KEY_ID=XXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXX
export AWS_BUCKET=XXXXXXXXXX

b. This is my development.rb (Note: Copy and paste without changing anything)

Paperclip.options[:command_path] = "/usr/local/bin/"

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['AWS_BUCKET'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
}

Be sure you rebundle your Rails app with the latest paperclip and aws-s3 gems. Also, make sure you quit your Terminal and run everything again since this is an update to your .bash_profile file.

I hope everything works out now.

于 2012-11-06T20:01:01.520 回答
2

您应该在 mac os的用户.bash_profile中定义ENV[]变量。

您应该执行“heroku config”来查看 S3 的 heroku 环境密钥并在本地环境中定义它。

例如:

$ heroku config

AWS_ACCESS_KEY_ID: your_S3_XXX_key<br />
AWS_SECRET_ACCESS_KEY: your_secret_XXX_key<br />
AWS_BUCKET: your_production_bucket<br />
DATABASE_URL: postgres://xxxxxxx<br />
[...]<br />

您应该在.bash_profile文件中复制 access_key 和 secret:

export AWS_ACCESS_KEY_ID=your_S3_XXX_key<br />
export AWS_SECRET_ACCESS_KEY=your_secret_XXX_key
export AWS_BUCKET=your_development_bucket => "Specify new bucket for your dev environement".
于 2012-08-01T15:01:29.770 回答
1

万一有人在做我做的同样愚蠢的事情——并制作一个本地脚本来导出所有 AWS 环境变量——确保你在生成 rails 服务器的同一个终端会话中获取它!如果您使用拆分窗口 (CMD SHIFT D),请记住,在一个窗口中获取正确的环境变量不会在另一个窗口中这样做。非常愚蠢的错误,但我确信(或至少有点希望)我不会是唯一一个成功的人。

于 2014-07-10T22:44:01.213 回答
0

您也可以简单地使用(当然填写正确的值):

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => 'AWS_BUCKET',
      :access_key_id => 'AWS_ACCESS_KEY_ID',
      :secret_access_key => 'AWS_SECRET_ACCESS_KEY'
    }
}
于 2012-12-14T03:46:01.530 回答
0

我有同样的问题,我有 config/application.yml (不确定它是否是遗留的东西或它来自哪里),但这允许在 rails 'codebase' 中设置环境变量。我忘了它在这里,在 heroku 中被忽略并且覆盖了一些未设置的设置。doh!

于 2017-01-19T08:21:01.393 回答