10

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)

Oll
  • 945
  • 1
  • 14
  • 23

2 Answers2

25

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.

Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • does this mean that we need to remove the line `gem "aws-s3", :require => "aws/s3"` from the gem file? – Parth Apr 13 '12 at 19:25
  • @Paarth With Paperclip >= 2.5.0, you no longer need the aws-s3 gem (it uses aws-sdk now). I don't know if leaving the aws-s3 gem in your Gemfile will cause any conflicts, though. – Dylan Markow Apr 13 '12 at 20:21
  • @Markow Thanks for quick reply, i will try and let you know. I am facing issue while upgrading my ruby from 1.8.7 to 1.9.3. Please have a look @ [PaperClip not working while upgrading to 1.9.3](http://stackoverflow.com/questions/10147038/ruby-with-paperclip-upgrading-1-8-7-to-1-9-3-paperclip-s3-upload-not-working) – Parth Apr 14 '12 at 03:20
  • @Markow, it worked without aws-s3 as you mentioned, but the problem i was facing is because of contentType config for paperclip model. Please check the link i mentioned in prev. comment for the resolution. – Parth Apr 15 '12 at 08:56
-2

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

asarig
  • 197
  • 2
  • 9