【发布时间】:2014-06-03 18:56:07
【问题描述】:
遇到奇怪的问题,无法理解问题所在。所有生产提交给heroku。我正在尝试将回形针附件存储在 s3 服务器上。但不能使它工作在生产和开发上。
game.rb:
has_attached_file :image,
:styles => { :big => "500x500",
:tiny => "25x25" },
:default_url => "/images/game/:style/missing.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:path => "games/:id/:style.:extension",
:bucket => 'my-assets'
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_attachment_file_name :image, :matches => [/png\Z/, /jpe?g\Z/]
config/initializers/s3.rb 文件:
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:bucket => "my-assets" }
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
config/s3.yml
development:
access_key_id: XXX
secret_access_key: YYY
bucket: my-assets
production:
access_key_id: XXX
secret_access_key: YYY
bucket: my-assets
尝试提交后,我得到了空白页面,服务器日志告诉我:
2014-04-22T17:03:05.984867+00:00 app[web.1]: Command :: identify -format %m '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv6[0]'
2014-04-22T17:03:05.985022+00:00 app[web.1]: Command :: identify -format %m '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv6[0]'
2014-04-22T17:03:06.087486+00:00 app[web.1]: Command :: convert '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv6[0]' -auto-orient -resize "25x25" '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv620140422-2-dyoalj'
2014-04-22T17:03:06.087486+00:00 app[web.1]: Command :: convert '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv6[0]' -auto-orient -resize "25x25" '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv620140422-2-dyoalj'
2014-04-22T17:03:06.337480+00:00 app[web.1]: Command :: file -b --mime '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv620140422-2-dyoalj'
2014-04-22T17:03:06.340733+00:00 app[web.1]: Command :: file -b --mime '/tmp/0241bb4e859805f30efd33cf186468f120140422-2-1093xv620140422-2-dyoalj'
2014-04-22T17:03:06.549137+00:00 app[web.1]: Command :: file -b --mime-type '/tmp/93d8a7cd8991a044877ff351da55677e20140422-2-15pyo7z'
2014-04-22T17:03:06.549137+00:00 app[web.1]: Command :: file -b --mime-type '/tmp/93d8a7cd8991a044877ff351da55677e20140422-2-15pyo7z'
2014-04-22T17:03:06.694015+00:00 app[web.1]: [paperclip] saving games/1/original.png
2014-04-22T17:03:06.694015+00:00 app[web.1]: [paperclip] saving games/1/original.png
2014-04-22T17:03:07.648471+00:00 app[web.1]: Completed 500 Internal Server Error in 7103ms
2014-04-22T17:03:07.648471+00:00 app[web.1]: Completed 500 Internal Server Error in 7103ms
2014-04-22T17:03:07.663040+00:00 app[web.1]:
2014-04-22T17:03:07.663040+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2014-04-22T17:03:07.663040+00:00 app[web.1]: app/controllers/games_controller.rb:50:in `block in update'
2014-04-22T17:03:07.663040+00:00 app[web.1]: app/controllers/games_controller.rb:49:in `update'
2014-04-22T17:03:07.663040+00:00 app[web.1]:
2014-04-22T17:03:07.663040+00:00 app[web.1]:
2014-04-22T17:03:07.663040+00:00 app[web.1]:
2014-04-22T17:03:07.663040+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2014-04-22T17:03:07.663040+00:00 app[web.1]: app/controllers/games_controller.rb:50:in `block in update'
2014-04-22T17:03:07.663040+00:00 app[web.1]: app/controllers/games_controller.rb:49:in `update'
尝试在开发(本地)服务器上进行测试时,错误有点不同:
[paperclip] saving /games/images/000/000/001/original/game.png
(0.4ms) ROLLBACK
Completed 500 Internal Server Error in 1210ms
Errno::ECONNREFUSED (Connection refused - connect(2) for "my-assets.my-assets.s3-website-us-east-1.amazonaws.com" port 443):
app/controllers/games_controller.rb:50:in `block in update'
app/controllers/games_controller.rb:49:in `update'
【问题讨论】:
标签: ruby-on-rails amazon-s3 paperclip