Search code examples
ruby-on-railsamazon-s3imagemagickpaperclipcommunityengine

Rails 3 and Communityengine Photo Uploads


I got my rails application using Communityengine up and running now, but somehow I can't make the image uploads work.

In the standard installation I would always get this error when I try to upload an image:

Photo /tmp/stream20130319-18602-13k89ab.gif is not recognized by the 'identify' command.

Imagemagick is correctly installed and the identify-command works. The permissions to the /tmp/ folder are correct, too. So I am clueless with this issue =(.

To work around this issue I tried to use Amazon S3 for storage since I don't mind where the images come from (See here). I copied the correctly filled out s3.yml to the applications /config/ folder. I am using gem "aws-sdk" in my Gemfile as suggested here: Paperclip; and I updated application_config.rb like this:

: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']              
    }
  },

When I try to edit a user profile or upload an image I get this error: uninitialized constant AWS::S3::Base Full Trace here:

 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'

Can anyone help me here? I am really stuck with this.


Solution

  • I resolved this issue now! The Jquery-Bootstrap branch of CommunityEngine uses paperclip 2.4.5 and this issue is resolved in newer Versions.

    I forked Communityengine on Github and updated the paperclip dependency to 2.7.4. Just replace this in community_engine.gemspec:

    s.add_dependency(%q<paperclip>, ["~> 2.4.3"])
    

    with this:

    s.add_dependency(%q<paperclip>, ["~> 2.7.4"])
    

    Another issue was that newer versions required "bucket" instead of "bucket_name" in the S3 credentials (which I messed up this way).