故障设置回形针+ AWS的S3图像存储在我们的Rails3 / Heroku的应用回形针、故障、图像、在我们的

2023-09-11 09:13:37 作者:6.油炸小可爱

我们已经建立了一个Rails应用程序,有多个用户,并为他们每个人的图像。我们的本地主机做所有的开发工作,我们的工作种子用户和放大器;照片......但现在,我们正在尝试使用S3进行图像存储,我们在......运行到错误总是在种子的迁移步骤,这样做时:

We have already built a rails app that has several users and an image for each of them. Doing all of the dev work on our localhost, we have working seeds for users & photos...but now that we are trying to use S3 for the image storage, we are running into errors during...always during the "seed" step of the migrations, when doing this:

耙分贝:迁移:重置

道歉的问题,但我们一直在敲打我们的头在这11小时,通过关于这个问题的所有相关协议栈的问题已经消失了。很多类似的帖子有NoSuchBucket错误和其他类型的问题,但我们没有建议改变有固定我们的问题......也许它关系到宝石,我们使用的是最新的版本?

Apologies for the question, but we have have been banging our heads on this for 11 hours, having gone through every related Stack question on the subject. A lot of similar posts had a NoSuchBucket error and other types of issues, but we none of the suggested changes have fixed our issue...maybe it's related to the newest versions of the gems we are using?

我们正在使用Rails 3.0.4和Ruby 1.8.7,2.3.8回形针,AWS-S3 0.6.2

We are using Rails 3.0.4, Ruby 1.8.7, Paperclip 2.3.8, aws-s3 0.6.2

我们正在增加种子初始用户和使用我们的seeds.rb文件在/迁移/文件夹中每个用户的照片。这总是在本地计算机存储时,文件和图像(使用回形针,但不是S3)工作的罚款。我们还测试了去除种子文件,并简单地创建与工作应用程序的新用户,并得到了同样的错误:

We are adding seeds for initial users and a photo for each user using our seeds.rb file in the /migrate/ folder. This always worked fine when storing files and images on local machine (using paperclip, but not S3). We also have tested removing the seeds file and simply creating a new user with the working app and got the same error:

凭据不是一个路径,文件,或   哈希

Credentials are not a path, file, or hash

有关用户模块中,我们测试了在我们同时通过(一个)YML文件和(b)直接在用户模型设置以下S3键的选项。 access_key_id:秘密 secret_access_key:秘密

For the user module, we have tested both the option where we set the following S3 keys through both the (a) yml file and (b) directly in the user model. access_key_id: 'secret' secret_access_key: 'secret'

我们试图从我们的本地主机这样做(没有住在Heroku上),同时,我们也试图通过Heroku上运行此。

We have tried doing this from our localhost (not yet live on heroku), and we have also tried running this through Heroku.

我们已经尝试看似按键的布局每一个排列,但我们最常得到的错误是这样的:

We have tried seemingly every permutation of the layout of those keys, but the error we most frequently get is this:

不能转换模块成散列

谷歌搜索此错误消息返回结果为零,所以我们不知道发生了什么那里。这是最令人沮丧的......貌似一切努力,让我们回到这个错误。

Googling this error message returns zero results, so we don't know what's happening there. This was the most frustrating part...seemingly every attempt got us back to this error.

我们也尝试过两种:

(1)硬编码的访问密钥在用户模型中,像这样的:

(1) hardcoding the access keys in the user model, both like this:

:access_key_id => ENV['accesskeyid'],
:secret_access_key => ENV['secretaccesskey'],

在这种情况下,我们经常得到这个错误:

In this case, we often got this error:

您没有同时提供所需的快捷键。请提供   access_key_id和secret_access_key。

You did not provide both required access keys. Please provide the access_key_id and the secret_access_key.

令人沮丧,因为我们总是有两个项目上市,有和没有引号测试,改变了顺序等等。

Frustrating, because we always had both items listed, tested with and without quotes, changing up the order, etc.

我们尝试了上述(a)与ENV ['accesskeyid']和(b)如果没有这些...有简单     blahblah =>'accesskeyid。

We tried it both (a) with the ENV['accesskeyid'] and (b) without those...with simply blahblah => 'accesskeyid'.

和(2)把钥匙进入阳明文件,像这样:

and (2) putting the keys into the yml file, like this:

has_attached_file :photo,
  :storage => :s3,
  :s3_credentials => "#{Rails.root}/config/s3.yml",
  :path => "/:photo/:filename"

本在阳明文件:

with this in the yml file:

development:
  access_key_id: accesskeyid
  secret_access_key: secretaccesskey
  bucket: ourbucketname
production:
  access_key_id: accesskeyid
  secret_access_key: secretaccesskey
  bucket: ourbucketname

我们试图与周围的按键单引号,没有。

We tried this with single quotes around the keys, and without.

我们也试图定义桶模型,而不是在YML文件,并得到了同样的错误。

We also tried defining the bucket in the model, rather than in the yml file, and got the same error.

和(3)中,将其设置是这样的:

and (3), setting it up this way:

如果Rails.env ==生产        S3_CREDENTIALS = {:access_key_id => ENV ['S3_KEY']:secret_access_key => ENV ['S3_SECRET']:斗=>ourbucket}其他        S3_CREDENTIALS = Rails.root.join(配置/ s3.yml)   结束

PS截图欣赏如何修改图片尺寸

if Rails.env == "production" S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "ourbucket"} else S3_CREDENTIALS = Rails.root.join("config/s3.yml") end

has_​​attached_file:照片,         :存储=>:S3,         :风格=> {:小=>50×50>,:拇指=>75x75>:中等=>   400×400>},         :PATH =>/:照片/:文件名

has_attached_file :photo, :storage => :s3, :styles => { :small => "50x50>", :thumb => "75x75>", :medium => "400x400>"}, :path => "/:photo/:filename"

随着我国阳明文件中的内容相同。

With the same contents in our yml file.

这给了我们这个错误:

凭据是不是一个文件,路径或哈希

credentials are not a file, path, or hash

当然,我们四核对,我们有正确的访问密钥(从我们的AWS账户),并测试设置散列的几种不同的方法,但从来没有得到我们想要的。

Naturally, we quadruple-checked that we had the correct access keys (from our AWS account) and tested several different ways of setting up the hash, but never got what we wanted.

下面是Gemfile中的相关部分:     创业板AWS-S3',:要求=>'AWS / S3'#For亚马逊储存影像     创业板曲别针

Here is the relevant portion of Gemfile: gem 'aws-s3', :require => 'aws/s3' #For Storing Images on Amazon gem 'paperclip'

作为另一种尝试,我们试图用宝石right_aws,相反,在Gemfile中,但是这导致了这个错误:

As another attempt, we tried to use the gem right_aws, instead, in the Gemfile, but this resulted in this error:

没有这样的文件加载 - AWS / S3(你   可能需要安装AWS-S3宝石)

no such file to load -- aws/s3 (You may need to install the aws-s3 gem)

请注意,我们一直在做这一切的,打所有这些错误做从本地主机迁移,而不是从现场Heroku的应用程序,但甚至不能突​​破这个简单的种子用户的步骤。

Note, we have been doing all of this and hitting all of these errors doing migrations from from localhost, not from the live Heroku app, but couldn't even get past this simple 'seed users' step.

目前,我们的桶名为media.oururl.com。有一些问题,有在桶的名字时期?

Currently, our bucket is titled media.oururl.com. Is there some issue with having periods in the bucket name?

要问Heroku的人了解,因为好,但考虑到多么惊人这个社会,我希望你一个人知道我们在做什么错了。

Going to ask the heroku guys about this, as well, but considering how amazing this community is, I am hoping one of you knows what we're doing wrong her.

MUCH AP preciated - 希望这可以帮助其他人谁跟着我们后面

MUCH appreciated - and hopefully this helps others who follow behind us.

推荐答案

非常好的问题。我花了相当长的一段时间了类似的问题,前一段时间

excellent question. I spent quite some time with a similar issue a while ago

首要的问题是,你需要将以下code到它自己的初始化文件:

The primary issue is that you need to move the following code into it's own initializer file:

if Rails.env == "production" 
   S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "ourbucket"} 
 else 
   S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end

那么,你应该添加下面一行到你的模型,你有* has_​​attached_file:照片*要添加的行。

Then, you should add the following line to your model where you have *has_attached_file :photo* The line to add is.

:s3_credentials => S3_CREDENTIALS,

这就是你失踪了。

此外,当你宣布你的水桶名,确保对标准的美国。如果您使用的其它位置,你就必须适当地更新路径。

Also, for when you declare your bucket name, make sure that is for standard us. If you use one of the other locations, you'll have to update the path appropriately.

希望这有助于!