10
votes

I am getting the following error when trying to upload an image using paperclip and s3 storage. The app worked fine uploading locally, but when I've made the required changes to use s3 I get the following:

NameError in ImagesController#create

uninitialized constant AWS::S3::Base

Gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.3'

gem 'sqlite3'

group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'dynamic_form'
end

gem 'aws-sdk'
gem 'paperclip'

models/Image.rb

class Image < ActiveRecord::Base
    has_attached_file :file, 
                      :styles => {
                          :featured => "970x560>", 
                          :thumb => "192x112>" 
                      },
                      :storage => :s3,
                      :s3_credentials => "#{Rails.root}/config/amazon_s3.yml"
end

config/amazon_s3.yml

bucket: myapp-dev
access_key_id: ####################
secret_access_key: ################################

Bundled gems: aws-sdk (1.2.5) paperclip (2.4.5) rails (3.1.3)

2
You probably need to include AWS::S3 somewhere.Robin

2 Answers

25
votes

Paperclip 2.4.5 still uses the aws-s3 gem. (The README on Github refers to aws-sdk, but that's only for the unreleased master branch).

Change your Gemfile line to:

gem "aws-s3", :require => "aws/s3"

or use the master branch instead of the stable version (which of course has some risk involved):

gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
gem "aws-sdk"

UPDATE: Paperclip 2.5.0, released on 1/13/2012, now uses aws-sdk.

-2
votes

whomever decided to kill paperclip to windows user did a good job.

bundle install

Fetching git://github.com/thoughtbot/paperclip.git
remote: Counting objects: 5602, done.
remote: Compressing objects: 100% (2419/2419), done.
remote: Total 5602 (delta 3868), reused 4704 (delta 3065)
Receiving objects: 100% (5602/5602), 855.88 KiB | 314 KiB/s, done.
Resolving deltas: 100% (3868/3868), done.
error: unable to create file test/fixtures/question?mark.png (Invalid argument)

so checking out gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git" directly does not solve the issue. gem "aws-s3", :require => "aws/s3" solves the issue for now but it probably means no update to the 2.5.0 for now