使用Paperclip和Amazon s3上传照片时缺少凭据

时间:2012-02-23 08:52:19

标签: ruby-on-rails amazon-s3 paperclip credentials

我在使用Paperclip将照片上传到S3时遇到问题。照片正确下载到网站,但尝试上传新的照片会出现“凭据丢失”消息。我已经尝试重置我的S3密钥,尝试更改编码中变量的访问权限,而不是更有效。我几乎可以肯定这是照片问题,因为如果我提交没有照片的表格,它会正确提交(尽管没有照片)。

这是模型(两个模型中的一个,但脚本是相同的):

class Outfit < ActiveRecord::Base
  attr_accessible :gender, :description, :user_id, :photo, :photo_file_name
  has_many :outfit_clothes, :dependent => :destroy
  has_many :like_relationships, :as => :liked, :dependent => :destroy
  belongs_to :user

  validates :gender,  :presence => true
  validates :photo_file_name, :presence => true
  has_attached_file :photo,
    :storage => :s3,
    :bucket => 'cold_fusion',
    :s3_credentials => {
      :access_key_id => ENV['S3_KEY'],
      :secret_access_key => ENV['S3_SECRET']
    }
end

以下是错误报告

OutfitsController中的RuntimeError #create

RuntimeError in OutfitsController#create

Missing credentials
Rails.root: /Users/calebballoch/rails_projects/product_tech

Application Trace | Framework Trace | Full Trace
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/default_signer.rb:47:in `initialize'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:371:in `new'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:371:in `block in <class:Configuration>'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:311:in `call'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:311:in `block in add_option_with_needs'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:307:in `block (2 levels) in add_option_with_needs'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:307:in `collect'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/configuration.rb:307:in `block in add_option_with_needs'
rspec-core/ruby/1.9.1/gems/aws-sdk-1.3.4/lib/aws/core/service_interface.rb:50:in `initialize'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:188:in `new'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:188:in `s3_interface'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:193:in `s3_bucket'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:197:in `s3_object'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:293:in `block in flush_writes'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:279:in `each'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/storage/s3.rb:279:in `flush_writes'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip/attachment.rb:214:in `save'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip.rb:468:in `block in save_attached_files'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip.rb:461:in `block in each_attachment'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip.rb:460:in `each'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip.rb:460:in `each_attachment'
rspec-core/ruby/1.9.1/gems/paperclip-2.6.0/lib/paperclip.rb:467:in `save_attached_files'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:410:in `_run_save_callbacks'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/callbacks.rb:264:in `create_or_update'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/persistence.rb:37:in `save'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/validations.rb:50:in `save'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/attribute_methods/dirty.rb:22:in `save'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:208:in `transaction'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:241:in `block in save'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/transactions.rb:240:in `save'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/abstract_controller/base.rb:167:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:425:in `_run__557217090004664767__process_action__2570414948427976814__callbacks'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/rescue.rb:17:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications.rb:53:in `block in instrument'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications.rb:53:in `instrument'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/abstract_controller/base.rb:121:in `process'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:45:in `process'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal.rb:193:in `dispatch'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_controller/metal.rb:236:in `block in action'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:65:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:29:in `call'
rspec-core/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
rspec-core/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
rspec-core/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:75:in `optimized_each'
rspec-core/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
rspec-core/ruby/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:532:in `call'
rspec-core/ruby/1.9.1/gems/hirefireapp-0.0.6/lib/hirefireapp/middleware.rb:27:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/etag.rb:23:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/conditionalget.rb:35:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/head.rb:14:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/flash.rb:247:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/session/abstract/id.rb:195:in `context'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/session/abstract/id.rb:190:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/cookies.rb:331:in `call'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/query_cache.rb:64:in `call'
rspec-core/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/callbacks.rb:28:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/reloader.rb:68:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/sendfile.rb:101:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
rspec-core/ruby/1.9.1/gems/railties-3.1.3/lib/rails/rack/logger.rb:13:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/methodoverride.rb:24:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/runtime.rb:17:in `call'
rspec-core/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/lock.rb:15:in `call'
rspec-core/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/static.rb:53:in `call'
rspec-core/ruby/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:456:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/content_length.rb:14:in `call'
rspec-core/ruby/1.9.1/gems/railties-3.1.3/lib/rails/rack/log_tailer.rb:14:in `call'
rspec-core/ruby/1.9.1/gems/rack-1.3.6/lib/rack/handler/webrick.rb:59:in `service'
/Users/calebballoch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/calebballoch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/calebballoch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"loSqVZPx/d/LO2zwlG5xGaqanDJYrzKCd43zbIx19Lk=",
 "outfit"=>{"photo"=>#<ActionDispatch::Http::UploadedFile:0x0000010650f300 @original_filename="Shirley欢欢11.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"outfit[photo]\"; filename=\"Shirley\xE6\xAC\xA2\xE6\xAC\xA211.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @tempfile=#<File:/var/folders/8f/8fdj0RXTE3SPyd7COgaQ1k+++TI/-Tmp-/RackMultipart20120223-46528-16vxkb0>>,
 "gender"=>"1",
 "description"=>"asdfas"},
 "commit"=>"Create an outfit"}
Show session dump

Show env dump

Response

Headers:

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

是S3中的你的桶名'cold_fusion'

:bucket =&gt; 'cold_fusion'

确保使用正确的access_key和secret_key。

答案 1 :(得分:0)

我在VersionEye的测试环境中遇到了类似的问题。问题实际上是ENV ['S3_KEY']返回一个空字符串。即使使用fakeS3也是一个问题。花了我6个小时来弄明白。