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
Related
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.
I'm trying to use Fog /Carrierwave/ with Rackspace Cloud Files. I have bunch of uploaded images in my production server. I'm trying to upload these images to Rackspace Cloud Files using below rake task.
desc 'Transfer photos to rackspace'
task :photos => :environment do
photos = Photo.order(created_at: :desc).limit(10)
photos.each do |photo|
if photo.attachment?
photo.attachment.recreate_versions!
photo.save!
else
puts "================================= ATTACHMENT NOT FOUND: ID: #{photo.id}"
end
end
end
But I get following errors:
rake aborted!
undefined method `body' for nil:NilClass
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/storage/fog.rb:227:in `read'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/cache.rb:77:in `sanitized_file'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/cache.rb:116:in `cache!'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/versions.rb:225:in `recreate_versions!'
/home/zeck/code/bee/lib/tasks/bee.rake:9:in `block (4 levels) in <top (required)>'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:13:in `each'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:13:in `each'
/home/zeck/code/bee/lib/tasks/bee.rake:7:in `block (3 levels) in <top (required)>'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/bin/ruby_noexec_wrapper:14:in `eval'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/bin/ruby_noexec_wrapper:14:in `<main>'
It means images not stored in Rackspace Cloud Files. You guys have similar rake task for it? Please share it to me. Or guide me.
Thank you for advice :D
When you change the storage of a CarrierWave uploader from :file to :fog, it loses track of the original uploaded paths of the image files, so methods like recreate_versions! and store! won't be able to find the files to upload.
If you tell CarrierWave the old paths manually, it'll upload them to Cloud Files for you:
desc 'Transfer photos to rackspace'
task :photos => :environment do
photos = Photo.order(created_at: :desc).limit(10)
photos.each do |photo|
if photo.attachment?
# If you've overridden the storage path in the uploader, you'll need to
# use a different path here.
#
# "photo[:attachment]" is used to get the actual attribute value instead
# of the mounted uploader -- the base filename of the attachment file.
path = Rails.root.join('public', 'uploads', photo[:attachment])
unless path.exist?
puts "#{path} doesn't exist. Double check your paths!"
next
end
photo.attachment = path.open
photo.save!
puts "transferred #{photo.id}"
else
puts "================================= ATTACHMENT NOT FOUND: ID: #{photo.id}"
end
end
end
I've an uploader where I've implement the #filename method to get a custom and unique filename but it looks like this method is ignored before saving the file (I'm uploading to rackspace with the fog gem)
Here is the uploader:
class MyImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
...
def filename
if original_filename.present?
"#{secure_token}.#{file.path.split('.').last.downcase}"
else
super
end
end
...
private
def secure_token
var = :"##{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
end
And here is a test in the console (I'm testing an issue with large filenames that I thought was solved with the custom #filename method):
1.9.3-p392 :002 > f = File.open('/Users/myuser/Desktop/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png')
=> #<File:/Users/myuser/Desktop/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png>
1.9.3-p392 :003 > my_model_instance.image = f
Errno::ENAMETOOLONG: File name too long - /Users/myuser/app/tmp/uploads/20130509-1723-16769-8458/thumb_lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat.png
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `initialize'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `open'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `block in copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1370:in `open'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1370:in `copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:477:in `copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:396:in `block in cp'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1531:in `fu_each_src_dest0'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:205:in `copy_to'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:121:in `block in cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:231:in `block in cache_versions!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:216:in `each'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:216:in `cache_versions!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `each'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/mount.rb:315:in `cache'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/mount.rb:173:in `image='
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/bundler/gems/carrierwave-mongoid-28a9b718d42b/lib/carrierwave/mongoid.rb:39:in `image='
So I think that I need to modify the filename before being saved in order to get the custom filename fully working because actually the file only is rename after being uploaded to Rackspace (only if the filename it's not so large)
The upload is exploding during the caching step (which happens locally) rather than the saving step (which happens in fog). Reading the source, it looks like carrierwave has a method you can override to do just this: full_original_filename
If the problem you're trying to solve is to make the cached filename shorter, the following may work. If you want to change that filename later, you'll need to use the official solution for that in addition.
MAX_FILENAME_LENGTH = 64 # arbitrary limit, your milage may vary
def full_original_filename
filename = super
return filename if !filename.present?
extension = File.extname(filename)
basename = File.basename(filename, extension)[0...MAX_FILENAME_LENGTH]
basename + extension
end
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
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.