本文介绍了回形针和Amazon S3问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序在Heroku上运行。我使用曲别针为用户化身一些简单的图片上传和其他一些东西,我有S3设置为我的后端,一切似乎是工作的罚款试图推至中三的时候,除了我得到以下错误:

I have a rails app running on Heroku. I am using paperclip for some simple image uploads for user avatars and some other things, I have S3 set as my backend and everything seems to be working fine except when trying to push to S3 I get the following error:

The AWS Access Key Id you provided does not exist in our records.

我以为我错贴我的访问密钥和秘密密钥,我又试了一次,仍然没有运气。想也许这只是一个车钥匙我停用它,并生成一个新的。仍然没有运气。

Thinking I mis-pasted my access key and secret key, I tried again, still no luck. Thinking maybe it was just a buggy key I deactivated it and generated a new one. Still no luck.

现在这两个键我已经使用OS X上的S3浏览器应用程序,并且已经能够连接到每查看我目前的桶,并添加/删除桶。有什么我应该寻找出?我有我的应用程序的S3和回形针设置像这样

Now for both keys I have used the S3 browser app on OS X and have been able to connect to each and view my current buckets and add/delete buckets. Is there something I should be looking out for? I have my application's S3 and paperclip setup like so

development:
  bucket: (unique name)
  access_key_id: ENV['S3_KEY']
  secret_access_key: ENV['S3_SECRET']

test:
  bucket: (unique name)
  access_key_id: ENV['S3_KEY']
  secret_access_key: ENV['S3_SECRET']

production:
  bucket: (unique_name)
  access_key_id: ENV['S3_KEY']
  secret_access_key: ENV['S3_SECRET']

has_attached_file :cover,
    :styles => {
      :thumb => "50x50"
    },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => ":class/:id/:style/:filename"

编辑注:ENV ['S3_KEY']和ENV ['S3_SECRET']为我所用,直接把钥匙试图即使在Heroku的环境变量,它仍然无法正常工作

EDIT NOTE: The ENV['S3_KEY'] and ENV['S3_SECRET'] are environment variables in heroku which i have tried even using my keys directly and it still doesn't work

注:我刚刚加入的(唯一的名称)位,这些都不是真正存在 - 我也验证了斗的名字,但我甚至不认为这是越来越远。我也有我的Heroku的环境中正确设置增值经销商,让他们安装上开发

Note: I just added the (unique name) bits, those aren't actually there--I have also verified bucket names, but I don't even think this is getting that far. I also have my heroku environment vars setup correctly and have them setup on dev

推荐答案

您没有设置一个水桶。它在你的s3.yml文件,但你不读您的呼叫值 has_​​attached_file

You aren't setting a bucket. It's in your s3.yml file, but you aren't reading that value from your call to has_attached_file.

回形针S3文档:的

此外,要注意那些谁告诉你不要使用s3.yml文件Heroku的人。这是一种浪费,只是增加了抽象,买你什么都没有。你已经有你的ENV​​设置了你所需要的值,所以使用它们。

Also, pay attention to those people who are telling you not to use a s3.yml file with Heroku. It's a waste and just added abstraction that buys you nothing. You already have your ENV set up with the values you need, so use them.

我之前,我不想推的s3.yml文件Heroku的做到了这一点,但我想用一个用于测试和开发。在初始化,你可以做这样的事情:

I've done this before where I don't want to push an s3.yml file to Heroku, but I do want to use one for test and development. In an initializer you can do something like this:

# If an s3.yml file exists, use the key, secret key, and bucket values from there.
# Otherwise, pull them from the environment.
if File.exists?("#{Rails.root}/config/s3.yml")
  s3_config = YAML.load_file("#{Rails.root}/config/s3.yml")
  S3[:key] = s3_config[Rails.env]['key']
  S3[:secret] = s3_config[Rails.env]['secret']
  S3[:bucket] = s3_config[Rails.env]['bucket']
else
  S3[:key] = ENV['S3_KEY']
  S3[:secret] = ENV['S3_SECRET']
  S3[:bucket] = ENV['S3_BUCKET']
end

然后,当你正在设置回形针在模型中,您引用这样的值:

Then when you're setting up Paperclip in your model, you reference the value like this:

...
:s3_credentials => {
  :access_key_id => S3[:key],
  :secret_access_key => S3[:secret]
},
:bucket => S3[:bucket]

显然,这意味着你不想让你的s3.yml文件在您的git仓库(这真的,你不应该这样)。

Obviously, this means that you do not want to have your s3.yml file in your git repository (which really, you shouldn't anyway).

这篇关于回形针和Amazon S3问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:18