4

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

development:
  access_key_id: xxxxxxxx

   secret_code: xxxxx

メッセージが届いています

 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 アプリケーションでは、次の方法で資格情報を指定することもできます。

  • 上記の方法のいずれかを使用して構成初期化スクリプトを介して (例: RAILS_ROOT/config/initializers/aws-sdk.rb)。

  • RAILS_ROOT/config/aws.yml にある yaml 設定ファイル経由。このファイルは、デフォルトの RAILS_ROOT/config/database.yml ファイルのようにフォーマットする必要があります。

私は最後のステップをやっていると信じています。

Gemfile

gem 'rails', '3.1.3'
gem 'mysql'
gem 'koala'
gem 'paperclip'
gem 'aws-s3'
gem 'aws-sdk'
4

1 に答える 1

7

以下は私のために働いた:

  1. aws.rb という名前の初期化子にファイルを作成します
  2. aws.rb ファイルに以下を追加します。

    AWS.config(
    access_key_id: 'your_access_key',
    secret_access_key: 'your_secret_access_key')
    
  3. 次に、ペーパークリップのオプションは次のようになります。

    has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" },       
    :default_url => "missing_:style.png", :default_url => 'missing_:style.png', :storage =>   
    :s3, :bucket => "<my_bucket>"
    
于 2014-04-21T21:52:15.553 に答える