【发布时间】:2014-05-16 06:26:48
【问题描述】:
我收到以下错误:
The AWS Access Key Id you provided does not exist in our records.
我不确定为什么会收到此错误,因为我在我的 aws 安全凭证页面中显示了正确的访问密钥和秘密密钥(我已复制并粘贴了多次以驳斥拼写错误的可能性) .如果我能够登录并访问我的 STILL 空存储桶,为什么它会告诉我我的访问密钥不在他们的记录中?
这是我的 s3.yml:
GMAIL_USERNAME: <my email>
GMAIL_PASSWORD: <my password>
MONGOHQ_URL: <my mongoid url>
S3_BUCKET_NAME_DEVELOPMENT: <my development bucket>
S3_BUCKET_NAME_PRODUCTION: <my production bucket>
S3_BUCKET_NAME_TEST: <my test bucket>
AWS_ACCESS_KEY_ID: <my access key>
AWS_SECRET_ACCESS_KEY: <my secret key>
这是我的图片.rb:
class Picture
include Mongoid::Document
include Mongoid::Paperclip
embedded_in :datum, inverse_of: :pictures
has_mongoid_attached_file :attachment,
path: ':attachment/:id/:style.:extension',
storage: :s3,
url: ':s3_domain_url',
bucket: Proc.new{ |a| a.instance.s3_bucket },
s3_credentials: File.join(Rails.root, 'config', 's3.yml'),
styles: {
original: ['1920x1680', :jpg],
small: ['100x100', :jpg],
medium: ['250x250', :jpg],
large: ['500x500', :jpg]
},
convert_options: { all: '-background white -flatten +matte' }
def s3_bucket
if Rails.env.development?
ENV['S3_BUCKET_NAME_DEVELOPMENT']
else
ENV['S3_BUCKET_NAME_PRODUCTION']
end
end
end
这是我的 datum.rb:
class Datum
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paperclip
field :title, type: String
field :user_id, type: Integer
validates :title, presence: true
validates :user_id, presence: true
embeds_many :todo_items
embeds_many :pictures, cascade_callbacks: true
accepts_nested_attributes_for :pictures
end
这是我的datum_params 方法:
# Never trust parameters from the scary internet, only allow the white list through.
def datum_params
params.require(:datum).permit(:title, :user_id, :identifying_image, pictures_attributes: [:picture])
end
这是我的picture_params 方法:
def picture_params
params.require(:picture).permit(:datum_id, :attachment)
end
这是我用于上传的表单:
<%= bootstrap_form_for(picture, url: { action: :create }, html: { multipart: true }, remote: true ) do |f| %>
<%= f.file_field :picture, multiple: true, name: 'picture[picture]' %>
<%= f.submit 'Upload' %>
<% end %>
最初,我遇到了一个 strong_parameters 问题,rails4guides.com(答案如下的用户)能够帮助我克服。当我停止收到未经允许的参数错误并开始从 AWS 收到错误时,我知道我取得了进展。谁能看到我的凭据不起作用的任何原因?我应该在请求参数中看到有关我的访问密钥的任何信息吗?因为我现在没有。
【问题讨论】:
-
在你的 datum_params 中应该是图片属性(复数)。在您的图片参数中,您应该将附件的名称列入白名单。很奇怪,它似乎期望图片虽然在我看来它被命名为附件。我仍然会尝试 params.require(:picture).permit(:picture)。最后一个 :picture 指的是回形针附件的名称。
-
感谢您的建议!我今天下班后可以尝试这些,但我可以说的一件事是,如果我尝试
params.require(:picture).permit(:picture),它会抱怨Picture类没有名为picture的方法。如果我尝试使用jquery-fileupload-railsgem 让我能够一次上传多个文件,我是否需要对picture和pictures做更多的事情? -
嗯,使用回形针,您通常允许您的附件名称。在您的情况下,您会期望:附件。关于嵌套属性,在您允许的参数中对它的引用应该始终是复数。附:在使用 'pictures_attribute: [:picture]' 之前,您是否也遇到了完全相同的错误?
-
不,我没有。它创造了画面,但从来没有给我一个为什么事情没有被推到 s3 的原因。我唯一一次遇到无方法错误是在我遇到
params.require(:picture).permit(:picture)的时候。我将其更改为params.require(:picture).permit(:attachment)并将datum_params 方法主体更改为params.require(:datum).permit(..., pictures_attributes: [:pictures])。这符合你的建议吗?我可以在美国山区时间下午 6 点左右为您提供这些更改的结果。到目前为止,我非常感谢您的帮助。 -
如果这没有为我指明解决这个问题的方向,还有哪些其他信息对我的问题有用?我还要添加用于 file_field 的表单...
标签: ruby-on-rails-4 amazon-s3 mongoid paperclip strong-parameters