问题描述
我想上传图片在AWS。
I am trying to upload image at aws.
class Asset < ActiveRecord::Base
belongs_to :post
attr_accessible :image
has_attached_file :image, :styles => { :medium => "640x480>",
:thumb => "100x100#"},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'yourbucket'
end
s3.yml
s3.yml
development:
access_key_id: xxxxxxxx
secret_code: xxxxx
我得到一个消息
I am getting a message
AWS::Errors::MissingCredentialsError in PostsController#create
Missing Credentials.
Unable to find AWS credentials. You can configure your AWS credentials
a few different ways:
* Call AWS.config with :access_key_id and :secret_access_key
* Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
* On EC2 you can run instances with an IAM instance profile and credentials
will be auto loaded from the instance metadata service on those
instances.
* Call AWS.config with :credential_provider. A credential provider should
either include AWS::Core::CredentialProviders::Provider or respond to
the same public methods.
= Ruby on Rails
在一个Ruby on Rails应用程序,你也可以指定你的凭据 通过以下方式:
In a Ruby on Rails application you may also specify your credentials in the following ways:
-
通过一个配置的初始化脚本中使用任何上述方法(如RAILS_ROOT /配置/初始化/ AWS-sdk.rb)。
Via a config initializer script using any of the methods mentioned above(e.g. RAILS_ROOT/config/initializers/aws-sdk.rb).
通过位于RAILS_ROOT /配置/ aws.yml一个YAML配置文件。这个文件应该被格式化,如默认RAILS_ROOT /配置/ database.yml中文件。
Via a yaml configuration file located at RAILS_ROOT/config/aws.yml.This file should be formated like the default RAILS_ROOT/config/database.ymlfile.
我相信我做的最后一步。
I believe I am doing the last step.
的Gemfile
gem 'rails', '3.1.3'
gem 'mysql'
gem 'koala'
gem 'paperclip'
gem 'aws-s3'
gem 'aws-sdk'
pciated任何帮助AP $ P $
Any help appreciated
感谢
推荐答案
对我下面的工作:
- 创建你的初始化名为aws.rb文件
-
将在你的aws.rb文件中的以下内容:
- Create a file in your initializers called aws.rb
Put in the following in your aws.rb file:
AWS.config(
access_key_id: 'your_access_key',
secret_access_key: 'your_secret_access_key')
然后我的曲别针的选择是这样的:
Then my paperclip options looks like this:
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "missing_:style.png", :default_url => 'missing_:style.png', :storage =>
:s3, :bucket => "<my_bucket>"
这篇关于AWS ::错误:: MissingCredentialsError用曲别针和AWS-S3在轨3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!