Rails Carrierwave & s3: wrong number of arguments (2 for 1) - ruby-on-rails

new to CarrierWave, already loving it, so much better than Paperclip. Rails 3.2.1
I got it successfully working with local storage, but now trying to move to S3 and get a strange error on _url method (or the database column)
ArgumentError: wrong number of arguments (2 for 1)
Here's my uploader:
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :resize_to_limit => [200, 200]
def extension_white_list
%w(jpg jpeg gif png)
end
end
Everything works fine with local storage, and with S3 / fog the file gets uploaded and resized to S3, I can see it in the bucket; there just seems to be a problem with the field / field_url method which gives the error (2 for 1)
I've set non-public s3:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'xxx', # required
:aws_secret_access_key => 'yyy', # required
:region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = 'attachprod' # required
config.fog_public = false # optional, defaults to true
end
This is in my view:
<%= image_tag current_user.profile.picture_url %>
Full trace:
ArgumentError: wrong number of arguments (2 for 1)
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/fog-0.9.0/lib/fog/storage/models/aws/file.rb:126:in `url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/storage/fog.rb:148:in `authenticated_url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/storage/fog.rb:307:in `url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/uploader/url.rb:19:in `url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/uploader/versions.rb:159:in `url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/uploader/default_url.rb:8:in `url'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.0/lib/carrierwave/uploader/url.rb:27:in `to_s'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
from /Users/boudewijnvandongen/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any ideas, can't find much about this anywhere??
thnx

Turns out it needs an update of Fog gem to 1.3.1 All ok now

Related

Fog Gem - Access Denied on deleting S3 file

I'm using fog gem with carrierwave for uploading files to s3. The upload is ok and works perfectly, but, once I try to delete some instance of my model with the file attached, it sends the delete request and returns Access Denied, as bellow:
[fog][WARNING] fog: followed redirect to bucket-name.s3-us-west-2.amazonaws.com, connecting to the matching region will be more performant
Excon::Error::Forbidden: Expected(204) <=> Actual(403 Forbidden)
excon.error.response
:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>EB625F4C97AD368E</RequestId><HostId>E+We/GvBslMHoNn9nTT6Uw3t0qfJ9jXHCNkJRu0KOk5sk8WoFZbkaIyUB0WcWNPZuH2uCeoZTIo=</HostId></Error>"
:cookies => [
]
:headers => {
"Content-Type" => "application/xml"
"Date" => "Wed, 21 Dec 2016 14:48:53 GMT"
"Server" => "AmazonS3"
"x-amz-id-2" => "E+We/GvBslMHoNn9nTT6Uw3t0qfJ9jXHCNkJRu0KOk5sk8WoFZbkaIyUB0WcWNPZuH2uCeoZTIo="
"x-amz-request-id" => "EB625F4C97AD368E"
}
:host => "bucket-name.s3.amazonaws.com"
:local_address => "192.168.2.106"
:local_port => 51425
:path => "/uploads/conta/pdf_conta/375/1530_09-2016.pdf"
:port => 443
:reason_phrase => "Forbidden"
:remote_ip => "52.216.66.16"
:status => 403
:status_line => "HTTP/1.1 403 Forbidden\r\n"
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/expects.rb:7:in `response_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/response_parser.rb:9:in `response_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:388:in `response'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:252:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:215:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:272:in `rescue in request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/connection.rb:215:in `request'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/idempotent.rb:27:in `error_call'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/excon-0.54.0/lib/excon/middlewares/base.rb:11:in `error_call'
... 36 levels...
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/ronanlopes/HY Brazil/HyBrazil/bin/rails:9:in `<top (required)>'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/ronanlopes/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/ronanlopes/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/ronanlopes/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
The user token I'm using on my config has the AmazonS3FullAccess - AWS Managed policy, so it doesn't makes sense to me. Any ideas?
From what I see, you are setting the bucket_name variable on fog gem to be 'bucket-name', either that or you have edited it to post here.
Your config/initializer/carrierwave.rb should look something like this
CarrierWave.configure do |config|
config.fog_credentials = {
# Configuration for Amazon S3 should be made available through an Environment variable.
# For local installations, export the env variable through the shell OR
# if using Passenger, set an Apache environment variable.
#
# In Heroku, follow http://devcenter.heroku.com/articles/config-vars
#
# $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder
# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:region => ENV['S3_REGION']
}
# For testing, upload files to local `tmp` folder.
if Rails.env.test? || Rails.env.cucumber?
config.storage = :file
config.enable_processing = false
config.root = "#{Rails.root}/tmp"
else
config.storage = :fog
end
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
config.fog_directory = ENV['S3_BUCKET_NAME']
config.s3_access_policy = :public_read # Generate http:// urls. Defaults to :authenticated_read (https://)
config.fog_host = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}"
end
You may be setting ENV['S3_BUCKET_NAME'] or ENV['S3_ASSET_URL'] variables wrong, or even setting it mannually, check those in your .env file

Rails error with CarrierWave and S3 on Heroku, TypeError: no implicit conversion of nil into String

I am unable to upload images using CarrierWave and S3. I am using these gems:
gem 'carrierwave'
gem 'carrierwave-aws'
I have the configuration set up properly, in the code, environment variables, and on AWS:
CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = ENV["S3_BUCKET_NAME"]
config.aws_acl = 'public-read'
config.aws_credentials = {
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
region: ENV["AWS_REGION"]
}
config.cache_dir = "#{Rails.root}/tmp/uploads"
end
class ImageUploader < CarrierWave::Uploader::Base
storage :aws
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
One source said to include the cache_dir lines specifically for Heroku inside the uploader, but it seems to have no effect:
https://github.com/carrierwaveuploader/carrierwave/wiki/how-to%3A-make-carrierwave-work-on-heroku
Here is some standard code to save an image, but it gives an error:
> url = "https://dl.dropboxusercontent.com/u/22125572/Kira_opt.jpg"
> image = open(url)
> user = User.first
> user.image = image
TypeError: no implicit conversion of nil into String
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:171:in `join'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:171:in `cache_path'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:143:in `block in cache!'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/cache.rb:134:in `cache!'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/mount.rb:329:in `cache'
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/mount.rb:163:in `image='
from /app/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.11.2/lib/carrierwave/orm/activerecord.rb:39:in `image='
from (irb):4
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
It looks like the way I should have saved the remote image is using:
url = "https://dl.dropboxusercontent.com/u/22125572/Kira_opt.jpg"
user = User.first
user.remote_image_url = url
user.save
which means the url doesn't need to be opened at all.

Debugging Help: Ruby on Rails File Saving Failed with S3 and Carrierwave

I can't figure out for the life of me why this isn't working. I need debugging help and I am new to ruby on rails.
I want to store just a simple s3 file to my amazon bucket. That's it. I don't need this file attached to any row in a controller or stored in a database like all the examples show. I just need it to put it in the bucket. I think I might need to overwrite the store_dir in the avatar uploader but I wouldn't know how.
Below is what I have
The View:
= form_tag import_orders_path, :class => 'order-uploads', :multipart => true do
= file_field_tag 'upload[file]'
/ :file for just getting param[:file] from server
%br
= submit_tag "Import CSV", :class => 'submit-file'
The Controller:
uploader = AvatarUploader.new
puts YAML::dump(params[:upload][:file].path)
uploader.store!(params[:upload][:file])
File Path name:
/tmp/RackMultipart20150115-9225-o2c5hp
avatar.rb uploader
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# Choose what kind of storage to use for this uploader:
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
carrierwave.rb initializer
require 'fog'
require 'carrierwave'
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'my_key_id', # required
:aws_secret_access_key => 'my_secret_key', # required
:region => 'us-east-1', # optional, defaults to 'us-east-1'
}
config.fog_directory = "my_bucket"
end
Error:
NoMethodError (undefined method `id' for nil:NilClass):
app/uploaders/avatar_uploader.rb:16:in `store_dir'
app/controllers/orders_controller.rb:18:in `import'
NoMethodError (undefined method `id' for nil:NilClass):
app/uploaders/avatar_uploader.rb:16:in `store_dir'
app/controllers/orders_controller.rb:18:in `import'
you uploaded file should be
It should be app/uploaders/avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
# Choose what kind of storage to use for this uploader:
storage :fog
end
Then
uploader = AvatarUploader.new
uploader.store!(my_file)
uploader.retrieve_from_store!('my_file.png')

Problem with versions: Errno::ENOENT in Rails 3.1 RC

I am using Rails 3.1 RC and Carrierwave 0.5.4. Don't know if this is an issue with 3.1.
I verified that the path and file exists (http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif) in my S3 bucket.
When I do:
Photo.first.update_attributes!(:job_state => 'processing', :remote_attachment_url => 'http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif')
Error I get:
Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1813-612-6936/small_test.gif
Why is Carrierwave trying to access the local dir instead of S3?
My initializer looks like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => APP_CONFIG['amazon_access_key_id'], # required
:aws_secret_access_key => APP_CONFIG['amazon_secret_access_key'] # required
}
config.fog_directory = 'bucket_name' # required
config.fog_host = 'http://cdn.site_name.com' # optional, defaults to nil
config.fog_public = true # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
My uploader class looks like:
# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/users/#{model.user.id}/#{model.class.to_s.underscore}s/#{model.id}"
end
# Create different versions of your uploaded files:
version :small do
process :resize_to_fill => [53,53]
end
version :medium do
process :resize_to_fill => [106,106]
end
version :large do
process :resize_to_fill => [212,212]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# https://github.com/jnicklas/carrierwave/wiki
# Heroku has a read-only filesystem, so uploads must be stored on S3 and cannot be cached in the public
# directory. You can work around the caching limitation by setting the cache_dir in your Uploader classes
# to the tmp directory.
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
Full stack trace:
Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1827-5843-3673/small_test.gif
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `initialize'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `open'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `read'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:230:in `store'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:79:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:59:in `block in store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
... 16 levels...
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:246:in `save!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:168:in `block in update_attributes!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:166:in `update_attributes!'
from (irb):5
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:44:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>
In my uploader class, if I remove the versions, the upload succeeds without any errors.
Anyone coming across the same problem?
Hmmmm, I don't know exactly what the problem is, but I switched my gem file from:
gem 'carrierwave', :git => 'http://github.com/jnicklas/carrierwave.git'
to
gem 'carrierwave', '0.5.4'
The problem seems to have gone away. There is something definitely wrong with the master version...
Hope this helps someone who comes across the same issue on Rails 3.1 RC and Carrierwave.
Its your code here
def cache_dir
"#{Rails.root}/tmp/uploads"
end
Your app is using that for processing the images.
Following command should do the trick. On Ubuntu it is like:
sudo apt-get install imagemagick

Carrierwave/Fog - Argument error, provider not recognized

I'm using Carrierwave 0.5.3 and Fog to upload images to Amazon-S3.
The setup works smoothly when running locally, no errors.
But when running on Heroku, uploads fail with this message:
2011-03-31T12:53:46-07:00 app[web.1]: ArgumentError ( is not a recognized storage provider):
2011-03-31T12:53:46-07:00 app[web.1]: app/controllers/useditems_controller.rb:36:in `create'
I've got an initializer:
# /config/initializers/fog.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'secret',
:aws_secret_access_key => 'also secret',
:region => 'eu-west-1'
}
config.fog_directory = 'jabberwocky'
end
And an uploader:
# /app/uploaders/image_uploader.rb
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
include CarrierWave::RMagick
# Choose what kind of storage to use for this uploader:
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"useditems"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_limit => [220, 2000]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
end
I've traced the error message to Fog, and it seems that Fog, under Heroku, isn't getting the config info from the initializer. :provider is somehow empty. But I'm stumped as to how to fix it.
Any help would be much appreciated.
I'm using:
rails 3.0.4
heroku 1.19.1
fog 0.7.1
ruby 1.9.2 under rvm
The error was due to the fact that I had mistakenly added the initializer to the .gitignore-file. Thus, it was never uploaded to Heroku.
Adding this for completeness...
After smashing my head against the wall for hours with this error message, I found out that I had this line at the beginning of the carrierwave initializer:
if Rails.env.test?
...
So the initializer was only considered in the test environment. After removing it, everything worked as expected.

Resources