当前位置:  开发笔记 > 编程语言 > 正文

无法在Rails中连接到AWS?我该怎么做才能调试?

如何解决《无法在Rails中连接到AWS?我该怎么做才能调试?》经验,为你挑选了1个好方法。

我已经在轨道中实现了回形针,正如各种教程所推荐的那样.在尝试上传照片时,我始终如一地获得以下内容:

AWS::S3::NoConnectionEstablished

    usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:213:in `connection'
/usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:69:in `request'
/usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `put'
/usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:241:in `store'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip/storage.rb:195:in `flush_writes'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip/storage.rb:192:in `each'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip/storage.rb:192:in `flush_writes'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip/attachment.rb:142:in `save'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:331:in `send'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:331:in `save_attached_files'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:324:in `each_attachment'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:323:in `each'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:323:in `each_attachment'
/Users/joshcutler/code/NiteMob/vendor/plugins/paperclip/lib/paperclip.rb:330:in `save_attached_files'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in `send'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in `evaluate_method'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:166:in `call'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:93:in `run'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:92:in `each'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:92:in `send'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:92:in `run'
/Users/joshcutler/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:276:in `run_callbacks'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:344:in `callback'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:251:in `create_or_update'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2539:in `save_without_validation'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1009:in `save_without_dirty'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/dirty.rb:79:in `save_without_transactions'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:229:in `send'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:182:in `transaction'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:196:in `save'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:196:in `save'
/Users/joshcutler/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2628:in `update_attributes'

这是我的模型声明:

attr_accessor :image_file_name
  has_attached_file :image, 
    :styles => { :medium => "300x300>", :thumb => "100x100>" },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :s3_headers => {"Expires" => 1.year.from_now.httpdate},
    :path => ":attachment/:id/:style/:basename.:extension",
    :bucket => "something_unique"

这是我的s3.yml的格式:

development:   
  access_key_id: "my_key" 
  secret_access_key: "my_secret_key" 
production:   
  access_key_id: "my_key"  
  secret_access_key: "my_secret_key"

有什么想法发生了什么?

谢谢!



1> ryanb..:

为了帮助调试,请尝试将paperclip从等式中取出并直接从Ruby访问Amazon S3.您可以使用s3sh打开IRB 的命令并加载aws-s3 gem 来执行此操作.s3sh在命令行中运行并尝试键入以下内容.

# connect to S3 using your credentials
AWS::S3::Base.establish_connection!(
  :access_key_id     => 'my_key',
  :secret_access_key => 'my_secret_key'
)

# Store an image on S3
S3Object.store("foo.jpg", open("path/to/foo.jpg"), "something_unique")

# See if it's on there
bucket = Bucket.find("something_unique")
bucket["foo.jpg"]

您可以在此处找到有关aws-s3 gem的更多信息.

推荐阅读
小色米虫_524
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有