我现在使用Communityengine启动并运行了我的rails应用程序,但不知何故我无法使图像上传工作。
在标准安装中,当我尝试上传图像时,我总是会得到这个错误:
Photo /tmp/stream20130319-18602-13k89ab.gif is not recognized by the 'identify' command.
Imagemagick已正确安装,并且identify-命令正常工作。/tmp/文件夹的权限也正确。所以我对这个问题一无所知=
为了解决这个问题,我尝试使用Amazon S3进行存储,因为我不介意图像来自哪里(见这里)。我复制了正确填写的s3。将Yml文件放到applications/config/文件夹中。我在我的Gemfile中使用gem"aws-sdk",如下所示:我更新了application_config。像这样::photo => {
:missing_thumb => '/assets/icon_missing_thumb.gif',
:missing_medium => "/assets/icon_missing_medium.gif",
:paperclip_options => {
:storage => 's3',
:styles => {
:thumb => {
:geometry => '100x66#',
:processors => [:cropper]
},
:medium => {
:geometry => '300x200#',
:processors => [:cropper]
},
:large => {
:geometry => '600x400#',
:processors => [:cropper]
},
:original => "1024>"
}
},
:validation_options => {
:max_size => 3,
:content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
}
},
:feature => {
:use_thumbs => true,
:paperclip_options => {
:storage => 's3',
:styles => {
:thumb => "100x66#",
:medium => '300x200#',
:large => "600x400#",
:original => '1024>'
}
},
:validation_options => {
:max_size => 3,
:content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
}
},
:clipping => {
:paperclip_options => {
:storage => 's3',
:styles => {
:thumb => "100x66#",
:medium => "300x200#",
:large => "600x400#",
:original => '1024>'
}
},
:validation_options => {
:max_size => 3,
:content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
}
},
当我尝试编辑用户配置文件或上传图像时,我得到这个错误:未初始化常量AWS::S3::Base这里有完整的跟踪:
paperclip (2.4.5) lib/paperclip/storage/s3.rb:101:in `block in extended'
paperclip (2.4.5) lib/paperclip/storage/s3.rb:79:in `instance_eval'
paperclip (2.4.5) lib/paperclip/storage/s3.rb:79:in `extended'
paperclip (2.4.5) lib/paperclip/attachment.rb:392:in `extend'
paperclip (2.4.5) lib/paperclip/attachment.rb:392:in `initialize_storage'
paperclip (2.4.5) lib/paperclip/attachment.rb:73:in `initialize'
paperclip (2.4.5) lib/paperclip.rb:448:in `new'
paperclip (2.4.5) lib/paperclip.rb:448:in `attachment_for'
paperclip (2.4.5) lib/paperclip.rb:337:in `block in has_attached_file'
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.11) lib/active_record/base.rb:497:in `initialize'
/home/martin/.bundler/ruby/1.9.1/communityengine-281d49916dbc/app/controllers/photos_controller.rb:104:in `new'
/home/martin/.bundler/ruby/1.9.1/communityengine-281d49916dbc/app/controllers/photos_controller.rb:104:in `create'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:460:in `block (2 levels) in _run__141873283__process_action__116704501__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:215:in `block in _conditional_callback_around_1705'
activesupport (3.2.11) lib/active_support/callbacks.rb:326:in `around'
activesupport (3.2.11) lib/active_support/callbacks.rb:310:in `_callback_around_1685'
activesupport (3.2.11) lib/active_support/callbacks.rb:214:in `_conditional_callback_around_1705'
activesupport (3.2.11) lib/active_support/callbacks.rb:459:in `block in _run__141873283__process_action__116704501__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:215:in `block in _conditional_callback_around_1704'
/home/martin/.bundler/ruby/1.9.1/communityengine-281d49916dbc/lib/community_engine/localized_application.rb:25:in `set_locale'
activesupport (3.2.11) lib/active_support/callbacks.rb:214:in `_conditional_callback_around_1704'
activesupport (3.2.11) lib/active_support/callbacks.rb:414:in `_run__141873283__process_action__116704501__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
rakismet (1.3.0) lib/rakismet/middleware.rb:10:in `call'
omniauth (1.1.2) lib/omniauth/strategy.rb:177:in `call!'
omniauth (1.1.2) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.2) lib/omniauth/builder.rb:48:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__284061703__call__288038654__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
这里有人能帮我吗?
Paperclip 2.4.5仍然使用aw -s3 gem。
将您的Gemfile行更改为:
gem "aws-s3", :require => "aws/s3"
或者使用主分支而不是稳定版本(这当然有一些风险):
gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
gem "aws-sdk"
更新:回形针2.5.0,于2012年1月13日发布,现在使用aws-sdk
对于第二个问题,我正在更新这个答案
最主要的问题是你需要把下面的代码移到它自己的初始化文件中:if Rails.env == "production"
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "ourbucket"}
else
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
然后,您应该将以下行添加到您的模型中,其中包含*has_attached_file:photo*要添加的行是。
:s3_credentials => S3_CREDENTIALS,
这是你以前错过的。
另外,当你声明你的桶名时,确保它是标准的。如果您使用其他位置之一,则必须适当地更新路径。
希望这对你有帮助!
我现在解决了这个问题!CommunityEngine的Jquery-Bootstrap分支使用了2.4.5的回纹针,这个问题在更新的版本中得到了解决。
我在Github上分叉了Communityengine,并将回形针依赖更新为2.7.4。只需将其替换为community_engine.gemspec
:
s.add_dependency(%q<paperclip>, ["~> 2.4.3"])
与这个:s.add_dependency(%q<paperclip>, ["~> 2.7.4"])
另一个问题是,新版本在S3凭据中需要"bucket"而不是"bucket_name"(我这样搞砸了)。